我在iPhone模擬器上的導航控制器中有一個非常奇怪的問題與UITableview。在顯示的單元格中,只有一些單元被正確渲染。他們都應該看起來一樣,但大多數都缺少我設置的附件,滾動視圖變化的細胞有附件,所以我懷疑它是某種細胞緩存發生,雖然內容是正確的每個細胞。我還設置一個圖像作爲背景,並且也僅顯示零星但我固定,通過改變UITableview呈現問題
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
(其也僅呈現與背景的隨機小區)
cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
我現在需要使用僅在隨機單元上顯示的附件來解決問題。我嘗試將代碼從cellForRowAtIndex移動到willDisplayCell,但它沒有任何區別。我輸入一個日誌命令來確認它正在每個幀中運行。
基本上它是一個表格視圖(UITableViewCellStyleSubtitle),它從服務器&獲取其信息,然後通過調用reload的委託方法進行更新。代碼是:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@", [NSString stringWithFormat:@"Setting colours for cell %i", indexPath.row]);
// Set cell background
// cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
cell.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"yellow-bar_short.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
// detailTableViewAccessory is a view containing an imageview in this view's nib
// i.e. nib <- view <- imageview <- image
cell.accessoryView = detailTableViewAccessory;
}
// Called by data fetching object when done
-(void)listDataTransferComplete:(ArticleListParser *)articleListParserObject
{
NSLog(@"Data parsed, reloading detail table");
self.currentTotalResultPages = (((articleListParserObject.currentArticleCount - 1)/10) + 1);
self.detailTableDataSource = [articleListParserObject.returnedArray copy]; // make a local copy of the returned array
// Render table again with returned array data (neither of these 2 fixed it)
[self.detailTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
// [self.detailTableView reloadData];
// Re-enable necessary buttons (including table cells)
letUserSelectRow = TRUE;
[btnByName setEnabled:TRUE];
[btnByPrice setEnabled:TRUE];
// Remove please wait message
NSLog(@"Removing please wait view");
[pleaseWaitViewControllerObject.view removeFromSuperview];
}
我只包含我認爲相關的代碼,如果需要可以提供更多代碼。我無法在iPhone上測試它,所以我不知道它可能只是一個模擬器異常或我的代碼中的錯誤。我一直從問題,任何想法得到很好的反饋?