我有一个UITableviewController有2个部分,每个部分都有1个自定义单元格。在第二个静态单元格中,我删除了一个UITableview并相应地实现了委托。
代码段。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView == self.activityTable) { // dynamic table
return 1;
}else {
return 2;
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView == self.activityTable) { // dynamic tableview
return [self.fetchActivityController.fetchedObjects count];
}else {
return 1; //static tableview
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView == self.activityTable) {
if ([self.fetchActivityController.fetchedObjects count] == 0)
return nil;
ADNetworkCell *cell=[self.activityTable dequeueReusableCellWithIdentifier:NSStringFromClass([ADNetworkCell class])];
ADActivity* activityObj = (ADActivity*)[self.fetchActivityController.fetchedObjects objectAtIndex:indexPath.row];
ADUser* nUser = [activityObj networkAgent];
[cell configWithAgent:nUser withActivity:[activityObj activity]];
cell.activityText.delegate=self;
return cell;
}else { // static tableview code
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView == self.activityTable) {
return 95.0f;
} else {
// The height of the 2nd static cell should be size of tableview with dynamic cell.
if (indexPath.section == 1) {
return 95 * [self.activityArray count];
}
}
return 44.0f;
}
未捕获的异常'NSRangeException',原因:'*** - [__ NSArrayI objectAtIndex:]:索引1超出边界[0 .. 0]'
***第一次抛出调用堆栈:(0 CoreFoundation 0x000000010d0b8f45 exceptionPreprocess + 165
类型的未捕获异常
1 libobjc.A.dylib 0x000000010c60bdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010cfa7b14 - [__ NSArrayI objectAtIndex:] + 164
3 UIKit 0x000000010b179516 - [UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 160
4 UIKit 0x000000010ae4929b - [UITableViewController tableView:indentationLevelForRowAtIndexPath:] + 65
5 UIKit 0x000000010abb7325 __53- [UITableView _configureCellForDisplay:forIndexPath:] _ block_invoke + 2226
6 UIKit 0x000000010ab15c10 + [UIView(动画)performWithoutAnimation:] + 65 7 UIKit 0x000000010abb6a5a - [UITableView _configureCellForDisplay:forIndexPath:] + 475
8 UIKit 0x000000010abc1e58 - [UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 828
9 UIKit 0x000000010abc1f3f - [UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
10 UIKit 0x000000010ab97307 - [UITableView _updateVisibleCellsNow:isRecursive:] + 3187
11 UIKit 0x000000010abcad1c - [UITableView _performWithCachedTraitCollection:] + 92
12 UIKit 0x000000010abb2884 - [UITableView layoutSubviews] + 223
13 UIKit 0x000000010ab20e40 - [UIView(CALayerDelegate)layoutSublayersOfLayer:] + 710
14 QuartzCore 0x000000010a7ec59a - [CALayer layoutSublayers] + 146
15 QuartzCore 0x000000010a7e0e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
16 QuartzCore 0x000000010a7e0cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
17 QuartzCore 0x000000010a7d5475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
18 QuartzCore 0x000000010a802c0a _ZN2CA11Transaction6commitEv + 486
19 UIKit 0x000000010aa66ca4 _UIApplicationHandleEventQueue + 7329
20 CoreFoundation 0x000000010cfe5011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
21 CoreFoundation 0x000000010cfdaf3c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000010cfda3f3 __CFRunLoopRun + 867
23 CoreFoundation 0x000000010cfd9e08 CFRunLoopRunSpecific + 488
24 GraphicsServices 0x000000010e733ad2 GSEventRunModal + 161
25 UIKit 0x000000010aa6c30d UIApplicationMain + 171
26 Agentdesks 0x000000010863164f main + 111
27 libdyld.dylib 0x000000010d59c92d start + 1 28 ??? 0x0000000000000001 0x0 + 1)libc ++ abi.dylib:终止于 NSException(lldb)