“Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” Error

前端 未结 7 1883
無奈伤痛
無奈伤痛 2021-02-13 16:24

I have an app that is selecting a person from their contacts list and takes their First name, last name and email. It then saves the first name to a nsmutablearray and puts it i

7条回答
  •  甜味超标
    2021-02-13 16:46

    The comments above about implementing -tableView:numberOfRowsInSection: are correct. The assertion is checking the returned value expecting it will increase.

    However since you didn't set your dataSource on the UITableView its calling (or not calling) a method that doesn't exist and getting 0.

    You need to set the myTableView.dataSource and (since you also implement the delegate protocol) myTableView.delegate to self.

    You're also likely to need something like

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
        ...
    }
    

    Unless you're registering that somewhere else or your storyboard has a "Prototype Cell" with the identifier "Cell" which your code asks for.

提交回复
热议问题