私は自分のView Controllerの1つにUITableViewを持っています。私のアプリケーションの複数の部分からのログメッセージが非同期で更新されています。それは問題なく動作しましたが、今日私は奇妙なバグに気付きました。約2時間後、テーブルビュー全体が空白になりました。セルもラインセパレータも背景色もありません。iPhone4 iOS5は、バックグラウンドセレクタからUITableViewを更新するのは安全ですか?
このテーブルビューには2つのエントリパスしかありません。
テーブルビューは、それのすべてのデータ「負け」と私はNSMutableArrayのは、容量不足で割り当てられたことがある疑いがある-(void)setContextActionWithTitle:(NSString *)title description:(NSString *)description
ことの一つに応答を停止させることができるもの
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;
}
。それは非常に迅速に最大容量に達するでしょう。上記の方法で投稿されたメッセージの一部は、performSelectorInBackground
へのコールに由来しています。私のバックグラウンドセレクタの1つがNSMutableArrayの容量をヒットし、それを再割り当てできないことがありますか?しかし、再び、空のテーブルビューにもセルがあるはずなので、ライン区切りを見ることができるはずです。
をsetContextActionWithTitle:description:
に、performSelectorOnMainThread
と折り返しますか?
は、それがテーブルビューを更新するために、2つの別々の呼び出しが行われていると何とか彼らは矛盾した状態でテーブルを残していることだろうか? (私はここで何か例外はありません)
これは非常に困惑している動作です、私はそれをデバッグする任意のヘルプに感謝したい!
ハハ、はっきりとポイントに、私はあなたがバックグラウンドスレッドからのUIKitオブジェクトにできることの非常に限られた数があり –
ことを避けるために、自分のコードを書き直します。それは十分に文書化されている。サポートされていると明示的に文書化されていない場合は、実行しないでください。 – bbum
ええ、ええ、私は知っています。良い音のために作ることはありません。 –