Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:

前端 未结 22 1395
长情又很酷
长情又很酷 2020-11-22 10:10

So I was making an rss reader for my school and finished the code. I ran the test and it gave me that error. Here is the code it\'s referring to:

- (UITableV         


        
22条回答
  •  借酒劲吻你
    2020-11-22 11:07

    You're using the dequeueReusableCellWithIdentifier:forIndexPath: method. The documentation for that method says this:

    Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

    You didn't register a nib or a class for the reuse identifier "Cell".

    Looking at your code, you seem to expect the dequeue method to return nil if it doesn't have a cell to give you. You need to use the dequeueReusableCellWithIdentifier: for that behavior:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    

    Notice that dequeueReusableCellWithIdentifier: and dequeueReusableCellWithIdentifier:forIndexPath: are different methods. See doc for the former and the latter.

    If you want to understand why you'd want to ever use dequeueReusableCellWithIdentifier:forIndexPath:, check out this Q&A.

提交回复
热议问题