Я новичок в разработке IOS.Я создаю UITableView с данными, но в последней строке это не строка данных, которая называется «загрузить больше элемента» (это отображаемое имя не подходит. Я изменю его позже, возможно, после того, как исправлю эту проблему)
«Load more item» включает 2 функции: при выборе последней строки эта таблица автоматически добавит 4 строки.При повторном выборе эти 4 новые строки будут удалены.и снова.
Но когда я во второй раз выбрал «загрузить больше элемента», появляется «Полученный сигнал программы:« SIGABRT »».
... ...
[self.tableView beginUpdates];
// Error here, SIGABRT, EXC_BAD_INSTRUCTION
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
... ...
Я создал этот проект xcode вXcode 4.2.1, ios5 SDK, без ARC, но есть проблема во время выполнения.Здесь дано в коде:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [posts count] + 1;}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *postCellId = @"postCell";
static NSString *moreCellId = @"moreCell";
UITableViewCell *cell = nil;
NSUInteger row = [indexPath row];
NSUInteger count = [posts count];
if (row == count) {
NSLog(@"%@ - indexPath : %d",NSStringFromSelector(_cmd), [indexPath row]);
cell = [tableView dequeueReusableCellWithIdentifier:moreCellId];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:moreCellId] autorelease];
}
cell.textLabel.text = @"Load more items...";
cell.textLabel.textColor = [UIColor blueColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:postCellId];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:postCellId] autorelease];
}
Post *currentPost = [posts objectAtIndex:row];
cell.textLabel.text = [currentPost postTitle];
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.detailTextLabel.text = [currentPost postDescr];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
}
return cell;}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@",NSStringFromSelector(_cmd));
NSUInteger row = [indexPath row];
NSUInteger count = [posts count];
if (row == count) {
if(SIMPLE_FLAG_INT==0){
NSArray *newPosts = [feed detailPosts];
NSUInteger newCount = [newPosts count];
if (newCount) {
[self.posts addObjectsFromArray:newPosts];
[newPosts release];
NSMutableArray *insertIndexPaths = [NSMutableArray array];
for (NSUInteger item = count; item < count + newCount; item++) {
[insertIndexPaths addObject:[NSIndexPath indexPathForRow:item
inSection:0]];
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
SIMPLE_FLAG_INT = 1;
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionNone animated:YES];
}
}else{
SIMPLE_FLAG_INT = 0;
NSLog(@" ==> %d num of row in section 0 ",[self tableView:self numberOfRowsInSection:0]);
NSMutableArray *deleteIndexPaths = [NSMutableArray array];
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:6 inSection:0]];
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:5 inSection:0]];
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:4 inSection:0]];
[deleteIndexPaths addObject:[NSIndexPath indexPathForRow:3 inSection:0]];
[self.tableView beginUpdates];
// Error here, SIGABRT, EXC_BAD_INSTRUCTION
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
NSIndexPath *selected = [self.tableView indexPathForSelectedRow];
NSLog(@"%@ - indexPathForSelectedRow(selected row): %d",NSStringFromSelector(_cmd), [selected row]);
if (selected) {
[self.tableView deselectRowAtIndexPath:selected animated:YES];
}
} else {
PostViewController *postController = [[PostViewController alloc]
initWithNibName:@"PostView"
bundle:nil];
postController.post = [posts objectAtIndex:row];
[[self navigationController] pushViewController:postController
animated:YES];
[postController release];
} }
Вот вывод консоли:
2012-03-28 02: 20: 22.059 Feeder [4577: bf03] tableView: didSelectRowAtIndexPath:
2012-03-28 02: 20: 22.064 Фидер [4577: bf03] tableView: didSelectRowAtIndexPath: - indexPathForSelectedRow (выбранная строка): 7
2012-03-28 02: 20: 23.600Фидер [4577: bf03] tableView: didSelectRowAtIndexPath:
2012-03-28 02: 20: 23.601 Фидер [4577: bf03] ==> 8 номеров строк в разделе 0
Текущий язык: авто;текущая цель-c
2012-03-28 02: 21: 05.756 Фидер [4577: bf03] *** Ошибка подтверждения в - [UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableViewView.m: 995
2012-03-28 02: 21: 05.758 Фидер [4577: bf03] *** Завершение работы приложения из-за необработанного исключения «NSInternalInconsistencyException», причина: «Неверное обновление: недопустимое количество строк в разделе0. Количество строк, содержащихся в существующем разделе после обновления (8), должно быть равно количеству строк, содержащихся в этом разделе до обновления (8), плюс или минус количество строк, вставленных или удаленных из этого раздела (0 вставлено, 4 удалено). '
*** Стек вызовов при первом броске:
(
0 CoreFoundation 0x00fd75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0112b313 objc_exception_throw + 44
2 CoreFoundation 0x00f8fef8 + [повышение NSException: формат: аргументы:] + 136
3 Foundation 0x008193bb - [дескриптор NSAssertionHandlerFailureInMethod: объект: файл: номер_строки: описание:] + 116
4 UIKit 0x00094e8b - [UITableView (_UITableViewPrivate) _endCellAnimationsWithContext:] + 8420
5 UIKit 0x0008ITE: - конечный конец для пользователя [0x000841]1042 *
6 Feeder 0x0000356b - [FeedViewController tableView: didSelectRowAtIndexPath:] + 1371
7 UIKit 0x0008db68 - [UITableView _selectRowAtIndexPath: анимированный: scrollPosition * UIK0: 1040 * 040 * 810: 031: 083 * 810: 031: 050: 031: 031: 031: 050.: 050.:...: 10 *.- [UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219 * +1048 * * 1 049 * 9 Фонд 0x0079d79e __NSFireDelayedPerform + 441
10 CoreFoundation 0x00fb88c3 * тысяча пятьдесят-дв * CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 19
11 CoreFoundation 0x00fb9e74 __CFRunLoopDoTimer + +1220
12 CoreFoundation 0x00f162c9 __CFRunLoopRun + 1817
13 CoreFoundation 0x00f15840 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x00f15761 CFRunLoop 1063S 1563MunService 1063MunServer 1562MunServer 1562MunServeRunSermServServServServServServServServer 910RunServer 1063MunServer 1063MunServer 1062Mun0x00cd71c4 GSEventRunModal + 217
16 GraphicsServices 0x00cd7289 GSEventRun + 115
17 UIKit 0x00024c93 UIApplicationMain + 1160
18 Фидер 0x000027cd основной + 125
19 Фидер 0x00002745 старт + 53
20 ??? 0x00000001 0x0 + 1
Снимок экрана: