我的代碼在通過cellForRowAtIndexPath約九次後跳過if(cell == nil)時出現問題。然後我的表中的項目開始重複,每9個項目就這樣做。當我刪除if(cell == nil)行時,表格會很漂亮,所有數據都按正確的順序排列。但是,如果我滾動到表格的底部,我的應用程序崩潰,所以這不是一個好的解決方案。請任何想法?當我嘗試重新使用tableviewcells時,重複的TableViewCell會顯示出來......我如何獲得新的顯示?
謝謝!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
NSString *temp = [[views objectAtIndex:indexPath.row] objectForKey:@"racer"];
NSString *val = [[views objectAtIndex:indexPath.row] objectForKey:@"pointsScored"];
// Set up the cell...
cell.textLabel.text = temp;
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.detailTextLabel.text = val;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[temp release];
[val release];
}
return cell;
}
哇!非常感謝!情況就是這樣!但是,現在當我運行它並向下滾動時,出現此錯誤: 2010-07-12 15:48:05.753 TabTabTab [25374:20b] *** - [UICGColor isEqualToString:]:無法識別的選擇器發送到實例0x3d9edc0 2010-07-12 15:48:05.755 TabTabTab [25374:20b] ***由於未捕獲異常'NSInvalidArgumentException',原因:'*** - [UICGColor isEqualToString:]:無法識別的選擇器發送到實例0x3d9edc0' 任何想法?? – Rossi 2010-07-12 19:49:53
不要緊!我刪除了釋放線,事情進展順利!非常感謝你的幫助。我真的很感激 – Rossi 2010-07-12 20:05:47
沒有問題,但請看我更新的帖子。你不能只刪除'釋放'行,否則你將會泄漏這些對象,因爲它們永遠不會被釋放。相反,只是擺脫它們,因爲你不需要它們(請參閱我的代碼)。請將此問題標記爲已通過點擊旁邊的「複選框」回答 – iwasrobbed 2010-07-12 20:26:00