Assertion failure in dequeueReusableCellWithIdentifier:forIndexPath:

前端 未结 22 1025
长情又很酷
长情又很酷 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 10:47

    Just a supplement of the answers: There may be a time you set all things right, but you may accidentally add some other UIs in you .xib, like a UIButton: Just delete the extra UI, it works.

    0 讨论(0)
  • 2020-11-22 10:48

    Working with Swift 3.0:

    override func viewDidLoad() {
    super.viewDidLoad()
    
    self.myList.register(UINib(nibName: "MyTableViewCell", bundle: nil), forCellReuseIdentifier: "Cell")
    }
    
    
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = myList.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath) as! MyTableViewCell
    
    return cell
    }
    
    0 讨论(0)
  • 2020-11-22 10:48

    I had the same issue, was having the same error and for me it worked like this:

    [self.tableView registerNib:[UINib nibWithNibName:CELL_NIB_HERE bundle: nil] forCellReuseIdentifier:CELL_IDENTIFIER_HERE];
    

    Maybe it will be usefull for someone else.

    0 讨论(0)
  • 2020-11-22 10:52

    i had the same problem replacing with

    static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
       if (cell==nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    
        }
    

    solved

    0 讨论(0)
  • 2020-11-22 10:55

    In your storyboard you should set the 'Identifier' of your prototype cell to be the same as your CellReuseIdentifier "Cell". Then you won't get that message or need to call that registerClass: function.

    0 讨论(0)
  • 2020-11-22 10:55

    This might seem stupid to some people but it got me. I was getting this error and the problem for me was that I was trying to use static cells but then dynamically add more stuff. If you are calling this method your cells need to be dynamic prototypes. Select the cell in storyboard and under the Attributes inspector, the very first thing says 'Content' and you should select dynamic prototypes not static.

    0 讨论(0)
提交回复
热议问题