繁体   English   中英

点击UITableView的单元格,其他视图不会出现

[英]Tap on cell of UITableView and the other view doesn't appear

我有一个tableView带有一些搜索结果。 我已将第一个和第二个视图与“ storyboard Segue”从单元格连接到第二个视图。

这是在第一个ViewController中编写的代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    let indexPath = self.tableProva.indexPathForSelectedRow?.row

    let vc = segue.destination as! DettaglioNewViewController

    vc.titleLibro = posts[indexPath!].name
    vc.authorLibro = posts[indexPath!].author
    vc.ISBNLibro = posts[indexPath!].ISBN

}

在其他项目中,它工作正常,但在该项目中,它不起作用,以显示我必须点击并向右或向左滑动的第二个viewController。

看来问题出在图形上。 如果我尝试单击该单元格,则不会变为灰色。 如果我长按它会变成灰色

这有发生在其他人身上吗?

谁能帮我?

您应该使用'didSelectRowAtIndexPath'方法,以便针对特定单元格选择不同的视图。 采用.....

var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))

vc = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as DettaglioNewViewController
vc.loadView()

.....搜集所需的信息。

*信息示例*

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    myFavIndex = indexPath.row
    let storyBoard = UIStoryboard(name: "Main", bundle:nil)
    let view = storyBoard.instantiateViewControllerWithIdentifier("LoginVC") as! DettaglioNewViewController
    view.imageURL = self.imageArray[mySelectedIndex]
    view.titleString = self.titleArray[mySelectedIndex]
    self.presentViewController(view, animated: true, completion: nil)
}

在上面的示例中,我使用新的View Controllers图像和标题作为view.imageURLview.titleString通过[mySelectedIndex]从我选择的单元格信息中填充视图元素。 您应该能够使用IntUIImageString ,例如

您无需根据代码初始化控制器。 只需创建一个自定义segue并在表委托的'didSelect'方法中调用'performSegue'方法即可。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
      self.performSegueWithIdentifier("yourIdentifierInStoryboardForCustomSegue", sender: nil)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM