2011-02-02 77 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;

在這種情況下,我們手動釋放分配的內存。我希望,這工作

相關問題