У меня есть UITableView
с простым массивом в качестве источника данных. Я разработал специальный наконечник для специального UITableViewCell
, который отображается, когда массив пуст (т.е. когда приложение запускается первым).Как перезагрузить пользовательскую ячейку представления таблицы после удаления последней строки?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if ([self.wallet count] == 0)
return 1;
else return [self.wallet count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// If there isn't any coupon yet, then show the custom "No Coupon Yet" cell
if ([self.wallet count] == 0)
return [tableView dequeueReusableCellWithIdentifier:@"NoCouponCell" forIndexPath:indexPath];
else {
CouponCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CouponCell" forIndexPath:indexPath];
Coupon *coupon = [self.wallet objectAtIndex:indexPath.row];
[cell configureForCoupon:coupon];
return cell;
}
}
Так как я хотел бы добавить функциональность салфетки для удаления, я предоставил следующий метод для контроллера представления.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.wallet removeObjectAtIndex:indexPath.row];
// Creates a new, temporary array holding just the one index-path item
NSMutableArray *tmp = [[NSMutableArray alloc] initWithObjects:indexPath, nil];
// Tells the table view to delete the row with a nice animation
[tableView deleteRowsAtIndexPaths:tmp withRowAnimation:UITableViewRowAnimationAutomatic];
}
Однако, когда в представлении таблицы есть только одна строка, и я пытаюсь удалить ее, приложение падает. Зачем?
EDIT: информация об отладке сообщает, что поднят NSInternalInconsistencyException
.
Вы можете добавить точку останова исключение для вашего проекта и сказать нам, где именно приложение падает? – halileohalilei
Другое дело, вы также удаляете элемент, соответствующий вашей ячейке, из вашего массива при удалении ячейки? – halileohalilei
И какой журнал это показывает при сбое – Munahil