Swift UITableViewController didSelectRow在第二个单元格被选中时第一次调用



这就是我的奇怪问题。
我有一个使用storyboard的小应用。我有1个UITabBarController,它有2个标签:
- 1 UITableViewController(子类)
- 1 UIViewController(只是有一个UILabel,直到现在什么都不做)

UITableViewController被子类化并提供:
- numberOfSectionsInTableView(tableView: UITableView) -> Int
- tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
- tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
- tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

tableview有2个section(7和1行)
section 1中的行是自定义单元格,当被选中时不应该做任何事情。
第2节中的行是一个标准的UITableViewCell,应该开始下载。但是当我选择任何单元格tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)甚至不被调用,只有在选择另一个单元格(不一样)之后,didSelect将与我选择的第一个单元格一起调用。
另一个例子;(x,x)表示选择的indexPath
(1,0),什么也不做——>(0,6),(1,0)选择->(0,2),选择(0,6)->(1,0)、(0,2)选择

添加

:
-高光效果正常。只是tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)的召唤不是。
- tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath?被称为适当的


解决方案:在委托方法中有一点错别字。我实现了didDeselectRowAtIndexPath而不是didSelectRowAtIndexPath

您正在呼叫didDeselectRowAtIndexPath而不是didSelectRowAtIndexPath。你应该使用这个方法:

tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

请检查您的委托方法,它应该是;

tableView(tableView: UITableView, selectRowAtIndexPath indexPath: NSIndexPath)

最新更新