私はIOS開発の初心者です。私は のデータを持つUITableViewを構築しますが、最後の行では、 "load more items"というデータ行ではありません(この表示名はあまり良くありません)。"deleteRowsAtIndexPaths"を呼び出すと、UITableViewでSIGABRTを解決する方法
"load more item"には2つの関数が含まれます。 最後の行を選択すると、このテーブルは自動的に4行追加されます。 再度選択すると、これらの新しい4行が削除されます。そしてもう一度。
しかし、2回目に「load more item」を選択すると、「プログラム受信信号: 'SIGABRT'」と表示されます。
... ...
[self.tableView beginUpdates];
// Error here, SIGABRT, EXC_BAD_INSTRUCTION
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
... ...
は私がARCなしで、SDK IOS5、Xcodeの4.2.1でこのXcodeプロジェクトを構築しましたが、実行時に問題があります。ここでコードに与えられる:
2012-03-28 02:20:22.059フィーダー[4577:bf03]のtableView:didSelectRowAtIndexPath:
2012ここ
- (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]; } }
コンソール出力であります-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]セクション0
現在の言語で行の==> 8 NUM:オート。現在、Objective-Cの
2012-03-28 02:21:05.756フィーダー[4577:bf03]における***アサーション障害 - [のUITableView _endCellAnimationsWithContext:]、/SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m。 995
2012-03-28 02:21:05.758フィーダー[4577:bf03] ***キャッチされない例外 'NSInternalInconsistencyException'のためアプリを終了します、理由:無効な更新:セクション0の行数が無効です。 update(8)の後の既存のセクションに含まれる行の数(8)は、そのセクションに挿入または削除された行の数をプラスまたはマイナスします。削除されました)。
***最初のスローでのコールスタック:
(
0 CoreFoundationの0x00fd75a9 __exceptionPreprocess + 185
1 libobjc.A。dylib 0x0112b313 objc_exception_throw + 44
2 CoreFoundationの0x00f8fef8 + [NSExceptionレイズ:フォーマット:引数:] + 136
3ファンデーション0x008193bb - [NSAssertionHandler handleFailureInMethod:目的:ファイル:行番号:説明:] + 116
4のUIKit 0x00094e8b - [のUITableView(_UITableViewPrivate)_endCellAnimationsWithContext:] + 8420
5のUIKit 0x000841e8 - [のUITableView endUpdates] + 42
6フィーダ0x0000356b - [FeedViewControllerのtableView:didSelectRowAtIndexPath:] + 1371
7のUIKit 0x0008db68 - [のUITableView _selectRowAtIndexPath:アニメーション:scrollPosition:notifyDelegate:] + 1140
8のUIKit 0x00083b05 - [のUITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
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 CFRunLoopRunInMode + 97
15 GraphicsServices 0x00cd71c4 GSEventRunModal + 217
16 GraphicsServices 0x00cd7289 GSEventRun + 115
17のUIKit 0x00024c93 UIApplicationMain + 1160
18フィーダは、メイン+ 125
19フィーダー+ 53
20を開始0x00002745 0x000027cd? 0x00000001の0x0の+ 1つの
画面キャプチャ:
私は既にnumbeOfRowsInSectionメソッドを修正しました。 "return [posts count]" しかし、動作していないようです。 "SIGABRT"プログラムがまだ発生しています。 – sdev