ios - 什么时候调用协议(protocol)函数?

标签 ios swift

我在 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/

相关文章:

ios - 为什么静态库有10Mb,但使用它的.ipa只有4Mb?

ios - 在联系人应用程序中重新创建 ipad 搜索栏

ios - 从 CollectionView 的结果中显示 CollentView

swift - 在 Swift 中从 userInfo 获取键盘大小

ios - 从另一个应用程序打开设置应用程序

ios - 为什么我的类明明有 NSManagedObject 属性却出现错误?

ios - 如何使用 XCUIKeyboardKey 常量?

ios - 从 AppDelegate 导航时导航栏消失

swift - 如何在 Safari 应用程序扩展中获取事件选项卡?

ios - UITableViewCONtroller 中的快速多个单元格子类