2011-01-28 9 views
0

이 원활하지 않습니다 ... 아래 내 코드각 셀에 다중 레이블과 웹 뷰가있는 부드러운 테이블 뷰 스크롤? 때문에이있는 tableview 스크롤에 내가 8 레이블과의 tableview 의 각 셀에 웹보기를 삽입하고 ...있는 tableview 스크롤 부드럽게 만드는 방법

{ 
    NSMutableArray *arr=[[NSMutableArray alloc]init]; 
     arr =[appDelegate.recentlyaddedarray objectAtIndex:indexPath.row]; 

     NSString *cellValue = [arr objectForKey: @"title"]; 
    #if USE_CUSTOM_DRAWING 
     const NSInteger TOP_LABEL_TAG = 1001; 

     UILabel *topLabel; 


#endif 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    UIImage *indicatorImage = [UIImage imageNamed:@"arrow.png"]; 
    cell.accessoryView =[[[UIImageView alloc] initWithImage:indicatorImage] autorelease]; 


#if USE_CUSTOM_DRAWING 


    const CGFloat LABEL_HEIGHT =100; 
    arr =[appDelegate.recentlyaddedarray objectAtIndex:indexPath.row]; 
    appDelegate.totalComments=[arr objectForKey:@"totalComments"]; 
    appDelegate.totalViews=[arr objectForKey: @"totalViews"]; 
    appDelegate.totalVotes=[arr objectForKey: @"totalVotes"]; 
    appDelegate.textfield=[arr objectForKey: @"title"]; 
    appDelegate.mytextview=[arr objectForKey: @"verse"]; 
    appDelegate.userid=[arr objectForKey: @"user_id"]; 
    appDelegate.added_date=[arr objectForKey: @"addedDate"]; 
    appDelegate.username=[arr objectForKey:@"user_name"]; 
    appDelegate.profilepic=[arr objectForKey:@"profile_pic"]; 
    NSLog(@"%@",appDelegate.profilepic); 





    CGRect webFrame = CGRectMake(0.0, 0.0,80 ,80); 
    UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; 
    webView.userInteractionEnabled=FALSE; 
    [webView setBackgroundColor:[UIColor clearColor]]; 
    webView.opaque=NO; 
    NSString *htmlTempString = [NSString stringWithFormat:@"<html><body><img src=\"%@\" width=50 height=60 /></body></html>",appDelegate.profilepic]; 
    NSString *htmlTempString = [NSString stringWithFormat:@"\n%@\n %@\n\n\n\n Votes(%@) Views(%@) Comments(%@)",cellValue,appDelegate.added_date,appDelegate.totalVotes,appDelegate.totalViews,appDelegate.totalComments];  
[webView loadHTMLString:htmlTempString baseURL:nil]; 
[cell.contentView addSubview:webView]; 
    [webView release]; 







    topLabel = [[[UILabel alloc] initWithFrame: CGRectMake(70,0,240,LABEL_HEIGHT)] autorelease]; 
    [topLabel setNumberOfLines:-1]; 




    UILabel *Titlelable = [[[UILabel alloc] initWithFrame: CGRectMake(57,4,240,20)] autorelease]; 
    [cell.contentView addSubview:Titlelable]; 
    Titlelable.tag = TOP_LABEL_TAG; 
    Titlelable.backgroundColor = [UIColor clearColor]; 
    Titlelable.textColor = [UIColor whiteColor]; 
    Titlelable.font=[UIFont fontWithName:@"Arial" size:16]; 
    Titlelable.text = [NSString stringWithFormat:@"\n\n\n\n%@\n",cellValue]; 



    UILabel *usernamelabel = [[[UILabel alloc] initWithFrame: CGRectMake(68,20,240,20)] autorelease]; 
    [cell.contentView addSubview:usernamelabel]; 
    usernamelabel.tag = TOP_LABEL_TAG; 
    usernamelabel.backgroundColor = [UIColor clearColor]; 
    usernamelabel.textColor = [UIColor whiteColor]; 
    usernamelabel.font=[UIFont fontWithName:@"Arial" size:10]; 
    usernamelabel.text = [NSString stringWithFormat:@"\nBy %@\n",appDelegate.username]; 





    UILabel *Timelabel = [[[UILabel alloc] initWithFrame: CGRectMake(57,40,240,20)] autorelease]; 
    [cell.contentView addSubview:Timelabel]; 
    Timelabel.tag = TOP_LABEL_TAG; 
    Timelabel.backgroundColor = [UIColor clearColor]; 
    Timelabel.textColor = [UIColor greenColor]; 
    Timelabel.font=[UIFont fontWithName:@"Arial" size:12]; 
    Timelabel.text = [NSString stringWithFormat:@"\n\n\n\n%@\n",appDelegate.added_date]; 




    UILabel *votelable = [[[UILabel alloc] initWithFrame: CGRectMake(101,56,240,20)] autorelease]; 
    [cell.contentView addSubview:votelable]; 
    votelable.tag = TOP_LABEL_TAG; 
    votelable.backgroundColor = [UIColor clearColor]; 
    votelable.textColor = [UIColor whiteColor]; 
    votelable.font=[UIFont fontWithName:@"Arial" size:12]; 
    votelable.text = [NSString stringWithFormat:@"\n%@\n",appDelegate.totalVotes]; 




    UILabel *viewlable = [[[UILabel alloc] initWithFrame: CGRectMake(155,56,240,20)] autorelease]; 
    [cell.contentView addSubview:viewlable]; 
    viewlable.tag = TOP_LABEL_TAG; 
    viewlable.backgroundColor = [UIColor clearColor]; 
    viewlable.textColor = [UIColor whiteColor]; 
    viewlable.font=[UIFont fontWithName:@"Arial" size:12]; 
    viewlable.text = [NSString stringWithFormat:@"\n%@\n\n",appDelegate.totalViews]; 




    UILabel *commentlabel = [[[UILabel alloc] initWithFrame: CGRectMake(235,56,240,20)] autorelease]; 
    [cell.contentView addSubview:commentlabel]; 
    commentlabel.tag = TOP_LABEL_TAG; 
    commentlabel.backgroundColor = [UIColor clearColor]; 
    commentlabel.textColor = [UIColor whiteColor]; 
    commentlabel.font=[UIFont fontWithName:@"Arial" size:12]; 
    commentlabel.text = [NSString stringWithFormat:@"\n\n%@\n",appDelegate.totalComments]; 





    [cell.contentView addSubview:topLabel]; 
    topLabel.tag = TOP_LABEL_TAG; 
    topLabel.backgroundColor = [UIColor clearColor]; 
    topLabel.textColor = [UIColor lightGrayColor]; 
    topLabel.font=[UIFont fontWithName:@"Arial" size:12]; 

    UIImage *cellBack = [UIImage imageNamed:@"cell.png"]; 
    cell.backgroundView =[[[UIImageView alloc] initWithImage:cellBack] autorelease]; 
    topLabel.text = [NSString stringWithFormat:@"Votes( ) Views( ) Comments( )"]; 
// topLabel.text = [NSString stringWithFormat:@"\n%@\n\n\n\n Votes(%@) Views(%@) Comments(%@)",appDelegate.added_date,appDelegate.totalVotes,appDelegate.totalViews,appDelegate.totalComments]; 
// topLabel.text = [NSString stringWithFormat:@"\n%@\n %@\n\n\n\n Votes(%@) Views(%@) Comments(%@)",cellValue,appDelegate.added_date,appDelegate.totalVotes,appDelegate.totalViews,appDelegate.totalComments]; 
#else 
    cell.text = [NSString stringWithFormat:@"Cell at row %ld.", [indexPath row]]; 



#endif 

    return cell; 

    } 

답변

2

I 돈이다 당신을 불쾌하게하고 싶지는 않지만 기본적인 주제로 더 많은 연습을해야합니다.

예를 들어,이 코드 : 당신이 이전을 방출하지 않고 물체를 들고 변수에 새로운 객체를 할당하기 때문에

NSMutableArray *arr=[[NSMutableArray alloc]init]; 
arr =[appDelegate.recentlyaddedarray objectAtIndex:indexPath.row]; 

는, 누출을 생산하고 있습니다.

이 코드 : 당신은 기본적으로 첫 번째 조각처럼 동일 할 수 있기 때문에

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

은 쓸모가 없다. 셀을 다시 사용하지 않으므로 스크롤이 원활하지 않습니다. 이런 일에

변경을 : 당신이 셀에 새보기를 추가 모든 통화를 넣어

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    // everything else 
    // example: 

    UILabel *titleLabel = [[[UILabel alloc] initWithFrame: CGRectMake(57,4,240,20)] autorelease]; 
    [cell.contentView addSubview:titleLabel]; 
    titleLabel.tag = TOP_LABEL_TAG; 
    titleLabel.backgroundColor = [UIColor clearColor]; 
    titleLabel.textColor = [UIColor whiteColor]; 
    titleLabel.font=[UIFont fontWithName:@"Arial" size:16]; 

} 
// set values 
// example: 
UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag:TOP_LABEL_TAG]; 
titleLabel.text = [NSString stringWithFormat:@"\n\n\n\n%@\n",cellValue]; 

대신 // everything else의.

// set values 대신 이전에 설정 한 태그를 사용하여 추가 한보기의 속성을 변경할 수 있습니다.

Et ooila, 부드러운 스크롤링.

당신이 이런 짓을했다면 당신이 쓸모없는 괴물을 없애한다 : 당신의 대답은 내 문제 :) 덕분에 해결 등 빠른 회신

const CGFloat LABEL_HEIGHT =100; 
arr =[appDelegate.recentlyaddedarray objectAtIndex:indexPath.row]; 
appDelegate.totalComments=[arr objectForKey:@"totalComments"]; 
/../ 
appDelegate.profilepic=[arr objectForKey:@"profile_pic"]; 
NSLog(@"%@",appDelegate.profilepic); 
+0

감사 alots 다시 한 번 –

+0

마티아스의 마지막 부분 당신의 코드의 괴물을 제거하라는 질문에 답하십시오. 그게 어떻게 문제를 일으키는 지 이해할 수 없습니다. 비슷한 것을하고 있기 때문에 이해해주세요. – carbonr