2011-01-06 44 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?