2011-01-06 39 views
0

我使用的是自定義的uitablecellview像我以前做的。但是,不幸的是,這個時候,一個新的細胞appears.So,相同的代碼部分已經非常完美許多拋出一個異常以前的時間。唯一的區別是我放入細胞的圖像質量非常高。 你有什麼想法?或者我應該多解釋一下? 編輯 一些代碼:錯誤時,「新的」自定義uitablecellview apprear

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"CellView"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"SPViewControllCell" owner:self options:nil]; 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell=cellView; 
    self.cellView=nil; 
} 
UILabel *itemTitle=(UILabel*)[cell viewWithTag:1]; 
[itemTitle setFont:[UIFont fontWithName:@"Renaissance" size:24]]; 
itemTitle.text=[titles objectAtIndex:indexPath.row]; 

UIImageView *img=(UIImageView*)[cell viewWithTag:2]; 
img.image=[images objectAtIndex:indexPath.row]; 

return cell; 

}

異常: 「 'NSInvalidArgumentException' 的,理由是: ' - [UITableViewCell的objectAtIndex:]:無法識別的選擇發送到實例0x5f36be0' 」 謝謝您。

+2

什麼異常?這可能是內存問題或文件格式問題。 – MusiGenesis 2011-01-06 15:53:07

+1

有機會看到一些代碼?或拋出什麼異常?也使用沉重的圖像可能表明您遇到內存不足的問題 – Vladimir 2011-01-06 15:53:30

+0

似乎像標題或圖像已被回收,其中一個有它的單元格地址使用 – CiNN 2011-01-06 15:59:50

回答

1

我猜,但titles的東西,如創建數組:

-(void) viewDidLoad(){ 
    // this will give you an autoreleased object 
    titles = [NSArray arrayWithObjects:@"Foo",...]; 
    // titles will be released once the current event is handled 


    // try the alloc/init style method 
    titles = [[NSArray alloc] initWithObjects:... ]; 
    // this will create an array with the retain count still at 1, thus won't be released 

也是一樣的images

你有什麼是經典的內存管理問題,其中你認爲的一個參考點指的是NSArray,但事實上,該陣列已經過去了,事情已經被替換爲一個隨機的其他對象。

對於completness:

- (void) viewDidUnload { 
    // clean up after your self 
    [titles release]; 
    [images release]; 
} 
0

從異常的描述似乎你在呼喚** objectAtIndex:**從一個UITableViewCell類實例的方法。

我的問題,在你的代碼中,你的圖片的類型是什麼標題 ivar?