繁体   English   中英

什么时候调用协议功能?

[英]When does a protocol function get called?

我在viewController类中采用了一个协议,并定义了它的方法(只有一个方法)。 该方法假定更新最初为空的数组。 这是一些代码。

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
    }

产生致命错误:无法索引空缓冲区(lldb)

我的问题是,getContactData()在什么时候被调用? 我需要在tableView函数之前调用它,以便可以使数组中包含某些内容。

当iOS需要显示单元格时,将调用cellForRowAtIndexPath UITableViewDataSource其他方法也是如此

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM