我试图在UITableViewController出现时(通过segue)选择第一行。
我正在使用以下代码,该代码是我之前的Objective C项目继承的:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let customCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! IGANavlistTableCustomViewCell
// Code that sets the custom view cell
// Then...
// Selecting the first row by default
if(indexPath.row == 0)
{
let rowToSelect:NSIndexPath = NSIndexPath(forRow: 0, inSection: 0)
tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: UITableViewScrollPosition.None)
tableView.delegate?.tableView!(tableView, didSelectRowAtIndexPath: rowToSelect)
}
return customCell;
}
我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IGANavlistTableVC tableView:didSelectRowAtIndexPath:]: unrecognized selector sent to instance 0x79e21040'
如果有人可以提供帮助,我将不胜感激。
谢谢!
编辑:
这是我的didDeselectRowAtIndexPath方法:
var navaidSelected = [String]()
var listOfNavPoints = [[String]]()
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
{
// The selected object of the Array with all navaids data (i.e., the selected navaid) is converted to a string
self.navaidSelected = self.listOfNavPoints[indexPath.row]
}
答案 0 :(得分:4)
您忘记了实施func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
方法。
拨打delegate
时,您无需使用didSelectRowAtIndexPath
:
if(indexPath.row == 0)
{
let rowToSelect:NSIndexPath = NSIndexPath(forRow: 0, inSection: 0)
tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: UITableViewScrollPosition.None)
self.tableView(tableView, didSelectRowAtIndexPath: rowToSelect)
}
=== EDITED ===
将您的didDeselectRowAtIndexPath
更改为didSelectRowAtIndexPath
。