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

时间:2016-12-19 19:59:34

标签: ios swift uitableview cell

我有一个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我必须点击并向右或向左滑动。

似乎问题是图形化的。 如果我试图点击单元格不会变成灰色。如果我长按它就会变成灰色

这是否发生在其他人身上?

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

您应该使用'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执行此操作,例如

答案 1 :(得分:0)

您不需要从代码初始化控制器。只需创建一个自定义的segue并调用' performSegue' ' didSelect'表委托方法。

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