简体   繁体   English

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

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

I have a tableView with some results of a search. 我有一个tableView带有一些搜索结果。 I have connected the first and the second view with the "storyboard Segue" from the cell to the second view. 我已将第一个和第二个视图与“ storyboard Segue”从单元格连接到第二个视图。

This is the code written in the first ViewController: 这是在第一个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

}

In other project it works perfectly, but in this project it doesn't work, to show the second viewController I have to tap and swipe to the right or left. 在其他项目中,它工作正常,但在该项目中,它不起作用,以显示我必须点击并向右或向左滑动的第二个viewController。

It seems that the problem is graphic. 看来问题出在图形上。 If I try to click on the cell does not become gray. 如果我尝试单击该单元格,则不会变为灰色。 turns gray if I hold down long on it 如果我长按它会变成灰色

Has this happened to anyone else? 这有发生在其他人身上吗?

Can anyone help me? 谁能帮我?

You should use the 'didSelectRowAtIndexPath' method in order to segue to a different view for a specific cell. 您应该使用'didSelectRowAtIndexPath'方法,以便针对特定单元格选择不同的视图。 Use..... 采用.....

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

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

..... To segue needed information. .....搜集所需的信息。

* Information Example * *信息示例*

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)
}

In the above example I'm using the new View Controllers image and title as view.imageURL and view.titleString to populate that views elements from my selected Cells Information via [mySelectedIndex] . 在上面的示例中,我使用新的View Controllers图像和标题作为view.imageURLview.titleString通过[mySelectedIndex]从我选择的单元格信息中填充视图元素。 You should be able to do this with an Int , UIImage , String , eg 您应该能够使用IntUIImageString ,例如

You don't need to initialize your controller from the code. 您无需根据代码初始化控制器。 Just create a custom segue and call 'performSegue' method in 'didSelect' method of table delegate. 只需创建一个自定义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