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

前端 未结 7 1918
無奈伤痛
無奈伤痛 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:47

    You need to maintain count for contacts array and increment accordingly.
    and while creating indexPath you need to set appropriate indexPathForRow: and section count(if required).

    - (void)displayPerson:(ABRecordRef)person
    {
    
      ..........
    
    [contacts insertObject:firstName atIndex:0];
    
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; // you cant do this increment appropriately
    
     .........
    }
    

提交回复
热议问题