UITableView
을 구현하는 데 문제가 있습니다. 각 셀에는 UIImageView
, UILabel
이 있습니다. JSON을 사용하여 웹 서비스에서 데이터를 검색 할 때 지연로드가 사용됩니다.UITableView Stuck UIButton을 클릭 할 때
하위보기 (예 : UIView
)를 제거하고 TableView의 크기를 조정해야하는 버튼이 있습니다.
내 문제는 단추를 클릭하면 UITableView의 스크롤이 느려지 게된다는 것입니다. 내 응용 프로그램을 프로파일 링하면 UITableView의 UIImageView에서 누수가 표시됩니다.
여기 jQuery과 내 코드,
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.color = [UIColor blueColor];
if (cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
if (lblTitle==nil){
lblTitle =[[UILabel alloc]init];
}
if (thumbnailImage==nil){
thumbnailImage = [[UIImageView alloc]init];
}
}
[cell addSubview:lblTitle];
[cell addSubview:thumbnailImage];
// set frames for table view cell
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone){
lblTitle.frame = CGRectMake(110, 0, 210, 100);
thumbnailImage.frame = CGRectMake(5, 5, 100, 90);
activityIndicator.frame = CGRectMake(40, 30, 35, 35);
lblTitle.font = [UIFont fontWithName:@"Papyrus" size:16.0f];
}else{
lblTitle.frame = CGRectMake(215, 0, 590, 150);
lblTitle.font = [UIFont fontWithName:@"Papyrus" size:25.0f];
thumbnailImage.frame = CGRectMake(5, 5, 200, 140);
activityIndicator.frame = CGRectMake(85, 45, 75, 75);
}
lblTitle.numberOfLines = 2;
lblTitle.textColor = [UIColor colorWithRed:105/255.0f green:205/255.0f blue:220/255.0f alpha:1.0f];
lblTitle.backgroundColor = [UIColor clearColor];
thumbnailImage.tag = indexPath.row;
// display data
lblTitle.text = [[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"title"];
//lazy loding of images
DataContainer *currentContainer;
if (profImageDataContainer.count!=0)
currentContainer= [profImageDataContainer objectAtIndex:indexPath.row];
if(currentContainer.cellImage)
thumbnailImage.image = currentContainer.cellImage;
else{
//checking whether thumbnail is null
if (![[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"image"] isKindOfClass:[UIImage class]])
{
if ([self checkNetworkStatus:nil]){
if(![[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"thumbnail"] isEqualToString:@""] && ([[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"thumbnail"] rangeOfString:@".jpg"].location!=NSNotFound || [[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"thumbnail"] rangeOfString:@".jpeg"].location!=NSNotFound || [[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"thumbnail"] rangeOfString:@".png"].location!=NSNotFound))
{
activityIndicator.tag = indexPath.row;
// Start it animating and add it to the view
[activityIndicator startAnimating];
[cell addSubview:activityIndicator];
NSString *urlstr = [[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"thumbnail"];
urlstr = [urlstr stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *imgURL = [NSURL URLWithString:urlstr];
thumbnailImage.image=[UIImage imageNamed:@"albumsPlaceHolder.png"];
NSMutableArray *array = [[NSMutableArray alloc]initWithObjects:imgURL,[NSString stringWithFormat:@"%d", indexPath.row],activityIndicator,thumbnailImage, nil];
[self performSelectorInBackground:@selector(loadImageInBackground:) withObject:array];
}else
{
thumbnailImage.image=[UIImage imageNamed:@"albumsPlaceHolder.png"];
}
}
else
{
thumbnailImage.image=[UIImage imageNamed:@"albumsPlaceHolder.png"];
}
}
else
{
thumbnailImage.image=[[rssNewsArray objectAtIndex:indexPath.row] objectForKey:@"image"];
}
}
thumbnailImage=nil;
lblTitle=nil;
activityIndicator=nil;
return cell;
}
버튼 액션 미리
- (IBAction)actCloseTicker:(id)sender
{
[self.ticker pause];
self.ticker=nil;
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setBool:NO forKey:@"ticker"];
[def synchronize];
def=nil;
[self.tickerView removeFromSuperview];
if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
self.tblRSSNews.frame = CGRectMake(0, 0, 320, self.view.frame.size.height);
}
else
{
self.tblRSSNews.frame = CGRectMake(0, 0, 768, self.view.frame.size.height);
}
}
감사합니다.
여기서 lblTitle 및 thumbnailImage를 할당합니까? – kkocabiyik
결과로 새로운 셀을 생성 할 때 셀 식별자를 재사용하지 않기 때문에 지정된 식별자로 셀을 dequeued하지 않고 dequeueReusableCellWithIdentifier가 반환하지 않을 때마다 새 셀을 생성 할 수 있습니까? – ldindu
그리고 문제는 당신이 당신의 tableview를 당신의 imageview와 addSubview에 스크롤 할 때마다 틀린 것입니다. if (셀 == nil) 블록에서 뷰의 하위 뷰 수행 – Retro