Используя следующий код, я смог отобразить текстовое сообщение, когда нет данных для отображения в uitableView:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
if ([appDelegate.myDataArray count] == 0)
{
return 3;
}
return [appDelegate.myDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* myCellIdentifier = @"MyCell";
myAppDelegate *appDelegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
if ([appDelegate.myDataArray count] == 0)
{
if (indexPath.row == 2)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellIdentifier]; // only reuse this type of cell here
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.textLabel.text = (@"No Records Found");
return cell;
}
else
{
// return a blank row for spacing
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCellIdentifier]; // only reuse this type of cell here
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCellIdentifier] autorelease];
}
cell.textLabel.text = (@"");
return cell;
}
} ........
Моя проблема заключается в том, что я хочу иметь такое поведение, когда я удалилзаписей таблицы с использованием метода:
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
В настоящее время результатом является сбой при удалении последней записи: «... Количество строк в существующем разделе после обновления (3) должно быть равно количеству строк, содержащихся в этом разделе перед обновлением (1) ... "
Любые идеи о том, как сделать так, чтобы текст отображался на 3 строки вниз (как показано выше) и не зависатьпосле удаления последней записи при удалении?
Спасибо.