【发布时间】:2011-06-08 02:50:10
【问题描述】:
我在方法中以编程方式定义了一个自定义标题视图:
ViewForHeaderInSection
自定义视图内部是一个 UIButton,它有一个目标操作 method:"foodDeleteButtonPressed"。我还将按钮的标签变量设置为节号。
这是该方法的实现
-(void)foodDeleteButtonPressed:(id)sender
{
NSInteger index = [sender tag];
NSLog(@"Delete button pressed for section: %d", index);
FoodItem *tmpItem = [Cart.foodItemsArray objectAtIndex:index];
int ct = [tmpItem.sidesArray count];
if(ct > 0)
{
NSLog(@"About to delete %d sides", ct);
[tmpItem.sidesArray removeAllObjects];
}
else
{
NSLog(@"The fooditem to be deleted has no side items");
}
NSLog(@"About to remove object from ffod items array");
[Cart.foodItemsArray removeObjectAtIndex:index];
[self.myOrderTable reloadData];
}
这个方法在没有行的情况下执行得很好:
[self.myOrderTable reloadData];
在删除部分后尝试重新加载数据来刷新视图的那一刻。 我的应用程序因以下堆栈跟踪而崩溃:
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]”
*** 首次抛出时调用堆栈:
(
CoreFoundation 0x010325a9 __exceptionPreprocess + 185
libobjc.A.dylib 0x01186313 objc_exception_throw + 44
CoreFoundation 0x010280a5 -[__NSArrayM objectAtIndex:] + 261
餐厅 0x00015c77 - [MyOrderViewController tableView:viewForHeaderInSection:] + 827
UIKit 0x0038de48 -[UITableView(UITableViewInternal) _delegateWantsHeaderForSection:] + 152
UIKit 0x004d8c01 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 116
UIKit 0x004d6d88 -[UITableViewRowDatanumberOfRows] + 108
UIKit 0x0038a677 -[UITableViewnoteNumberOfRowsChanged] + 132
UIKit 0x00397708 -[UITableView reloadData] + 773
餐厅 0x00011eac -[MyOrderViewControllerfoodDeleteButtonPressed:] + 444
UIKit 0x0031c4fd -[UIApplicationsendAction:to:from:forEvent:] + 119
UIKit 0x003ac799 -[UIControlsendAction:to:forEvent:] + 67
UIKit 0x003aec2b -[UIControl(Internal)_sendActionsForEvents:withEvent:]
重载数据抛出异常。我该如何解决?任何建议,将不胜感激。
【问题讨论】:
标签: ios uitableview