Obj-C, как я могу показать "не найдено строк" в UITableView и разрешить удаление всех строк, получая ошибку? - PullRequest
0 голосов
/ 05 февраля 2011

Я получаю следующую ошибку ...

Terminating app due to uncaught exception NSInternalInconsistencyException, 
reason: Invalid update: invalid number of rows in section 0.  The number of 
rows contained in an existing section after the update (1) must be equal to 
the number of rows contained in that section before the update (1), plus or 
minus the number of rows inserted or deleted from that section 
(0 inserted, 1 deleted).

Я только что добавил код, показывающий строку, в которой нет данных ...

- (NSInteger)tableView:(UITableView *)tableView 
       numberOfRowsInSection:(NSInteger)section {

    NSInteger num = [self.transactionsArray count];

    if (num == 0) {
        num = 1;
        [dataTableView setEditing: FALSE animated: NO];
    }
    return num;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
       cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     UITableViewCell *cell1;
    if(transactionsArray.count == 0) {
        self.navigationItem.leftBarButtonItem.enabled = FALSE;
        cell1 = [[[UITableViewCell alloc] initWithStyle:
               UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];

        cell1.textLabel.text = @"No transactons found";
        return cell1;
     }
         //Normal processing

Iпрошел до того, как возникла ошибка, и она возникла после завершения numberOfRowsInSection.Поэтому он обнаружил, что есть раздел, которого он не ожидал.

Как мне обойти это?

РЕДАКТИРОВАТЬ: Вот что происходит перед ошибкой

tableView:commitEditingStyle:forRowAtIndexPath:] [Line 630] commitEditingStyle start
tableView:commitEditingStyle:forRowAtIndexPath:] [Line 633] Delete now!
numberOfSectionsInTableView:] [Line 447] numberOfSectionsInTableView start
numberOfSectionsInTableView:] [Line 447] numberOfSectionsInTableView start
tableView:numberOfRowsInSection:] [Line 456] numberOfRowsInSection start

1 Ответ

0 голосов
/ 05 февраля 2011

Делай, что говорит исключение. Когда вы вызываете -deleteRowsAtIndexPaths:withRowAnimation:, чтобы удалить все строки в вашей таблице, вставьте одну строку с -insertRowsAtIndexPaths:withRowAnimation:, чтобы количество строк было правильным.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...