我試圖在UITableViewController出現(通過segue)時選擇第一行。在Swift中選擇UITableViewController中的第一行
我使用這是我從我以前的目標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]
}
你在使用故事板嗎?一切都正確嗎? –
錯誤指向didSelectRowAtIndexPath。你能爲此顯示代碼嗎? –