Ale*_*one 0 multithreading objective-c uitableview iphone-4 ios5
我在我的一个视图控制器上有一个UITableView,它使用来自我的应用程序的多个部分的日志消息进行异步更新.它工作得很好,但今天我发现了一个奇怪的错误.大约2个小时后,整个桌面视图变为空白.没有单元格,没有行分隔符,只有背景颜色.
此tableview只有2条入口路径.
NSMutableArray* tableViewCellData;
//in the init method:
tableViewCellData = [[NSMutableArray alloc]initWithCapacity:15];
-(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description
ContextConsoleLogItem* temp = [[ContextConsoleLogItem alloc] initWithDate:[NSDate date] title:title message:description contextAction:kNoContextAction];
[tableViewCellData insertObject:temp atIndex:0];
[contextActionTableView reloadData];
}
//pretty standard data source management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return kNumberOfSections;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [tableViewCellData count];
}
//here's how the cell displays itself.
#pragma mark -
#pragma mark Cell customization
-(void)configureCell:(UITableViewCell*) cell atIndexPath:(NSIndexPath*) indexPath
{
ContextConsoleLogItem* logItem = [tableViewCellData objectAtIndex:indexPath.row];
cell.backgroundColor = [UIColor blackColor];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont systemFontOfSize:9];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = logItem.message;
cell.textLabel.numberOfLines =3;
}
Run Code Online (Sandbox Code Playgroud)
什么可能导致tableview"丢失"所有数据并停止响应
-(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description
Run Code Online (Sandbox Code Playgroud)
我怀疑的一件事是NSMutableArray的容量不足.它会很快达到最大容量.使用上述方法发布的一些消息来自于调用performSelectorInBackground
.可能是我的一个后台选择器遇到NSMutableArray的容量并且无法重新分配它?但话说回来,即使是空的tableview仍然应该有单元格,所以我应该能够看到行分隔符.
我应该换我的电话来setContextActionWithTitle:description:
用performSelectorOnMainThread
?
是不是已经进行了两次单独的更新tableview的调用,并且他们以某种方式将表保持在一个不一致的状态?(我这里没有任何例外)
这是一个非常令人费解的行为,我很感激任何帮助调试它!