2011-02-02 75 views
1

您好我工作的UITableView自定义单元格的Twitter,为每个单元格我添加UIImageView(userPhoto),UILabel(名称),UILabel(tweet),UILabel(数据)要dealloc的所有元素,iPhone:如何dealloc自定义单元格标签

请到通过仪器工具ALLOC屏幕的附加拍摄的图像

当我运行的仪器工具

,它表现出一些不dealloc的,怎样的dealloc, 这是我的代码

//自定义表格视图单元格的外观。 - (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *identifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 


if(!cell) { 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:nil]; 

    //cell.selectionStyle = UITableViewCellSelectionStyleNone; 

UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(72,3,242,15)] ; 
name.text = (NSString*)[(Tweet*)[tweetArray objectAtIndex:indexPath.row] userName]; 
[name setFont:[UIFont fontWithName:@"Helvetica" size:13]]; 
name.textColor=[UIColor colorWithRed:250 green:250 blue:210 alpha:0.5]; 
[name setBackgroundColor:[UIColor clearColor]]; 



UILabel *date = [[[UILabel alloc]initWithFrame:CGRectMake(200,3,130,15)] autorelease]; 
date.text = (NSString*)[(Tweet*)[tweetArray objectAtIndex:indexPath.row] created_at]; 
[date setFont:[UIFont fontWithName:@"Helvetica" size:12]]; 
date.textColor=[UIColor colorWithRed:250 green:250 blue:210 alpha:0.5]; 
[date setBackgroundColor:[UIColor clearColor]]; 



UILabel * tweetLabel = [[UILabel alloc]initWithFrame:CGRectMake(72,20,242,60)] ; 
tweetLabel.text = (NSString*)[(Tweet*)[tweetArray objectAtIndex:indexPath.row] tweet]; 
tweetLabel.numberOfLines = 3; 
tweetLabel.textColor=[UIColor colorWithRed:252 green:148 blue:31 alpha:1]; 
[tweetLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]]; 
[tweetLabel setBackgroundColor:[UIColor clearColor]]; 

UIImageView *myImage = [[UIImageView alloc]initWithFrame:CGRectMake(6,10,58,60)] ; 
NSURL *url = [NSURL URLWithString:[(Tweet*)[tweetArray objectAtIndex:indexPath.row] image_url]]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 
[myImage setImage: [UIImage imageWithData:data]]; 

[cell.contentView addSubview:myImage]; 
[cell.contentView addSubview:tweetLabel]; 
[cell.contentView addSubview:name]; 
[cell.contentView addSubview:date]; 

[myTweetActivityIndi​​cator stopAnimating]; [myTweetActivityIndi​​cator setHidesWhenStopped:YES];

return cell; 

}

请指导我 谢谢This image for instrument tools one

回答

1

您可以使用

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:nil] autorelease]; 

对于其他标签,你也许可以使用

[date release]; [tweetLabel release]; [name release]; [myImage release]; 
+0

嗨Harinder,所有这些UIImage和UILabels发布,并且我做了自动释放,它显示NSUrl,[myImage setImage:[UIImage imageWithData:data]]中的一些泄漏; //此线很多与此,,,,即使我也释放UIImage和UILabel也显示dellocation没有发生,请告诉我 谢谢 – 2011-02-02 14:26:45

1

只要完成对象(例如,在addSubview之后),就必须发送release消息给您已使用init/alloc(名称,日期,tweetLabel,myImage)分配的所有对象。请注意,根据documentation,该视图由接收器保留。

+0

谢谢艾琳,我做了它的代码,但我错过了它后对你来说,我遇到了麻烦,像这样:NSData * data = [NSData dataWithContentsOfURL:url]; [myImage setImage:[UIImage imageWithData:data]];谢谢你,请检查这个并告诉,如何释放这个NSData对象数据,如果我释放该userPhoto不来,如果不是它不是deallocation如何处理这个 – 2011-02-02 14:37:45

1

尝试使用

NSData *data = [[NSData alloc] initWithContentsOfURL:url]; 

[MYIMAGE setImage:[UIImage的imageWithData:数据]]; [资料发布]; data = nil;

在这种情况下,我们手动释放分配的内存。我希望,这工作

相关问题