我在 viewController 类中采用了一个协议(protocol)并定义了它的方法(只有一种方法)。该方法假设更新一个最初为空的数组。这是一些代码。
var contact = ContactList()
func getContactData( entry: ContactListEntry ) {
contact.updateEntry(entry)
}
还有
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
self.detailViewController?.delgate = self
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel!.text = contact.entries [indexPath.row].firstName
return cell
}
出现 fatal error :无法索引空缓冲区 (lldb)
我的问题是,什么时候调用 getContactData ()?我需要在 tableView 函数之前调用它,这样我就可以使数组中的内容可用。
最佳答案
cellForRowAtIndexPath
在 iOS 需要显示单元格时被调用。 UITableViewDataSource
关于ios - 什么时候调用协议(protocol)函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29602391/