2014-11-18 3 views
1

Я могу использовать tableview для отображения нескольких изображений в каждой строке и прокручиваемых. на этот раз я использую cutomcell в tableview. Поэтому, когда прокрутка вверх и вниз немного липкая, она должна течь без прилипания или измельчения. IOS7 работает отлично, но проблема с IOS8, поэтому кто-нибудь предлагает мне сделать эту прокрутку лучше.UITableView не может сгладить прокрутку с помощью IOS8 в iphone sdk?

Мой код ниже cellForRowAtIndexPath:

CellHomeFeedViewController *cell = (CellHomeFeedViewController*)[tableView dequeueReusableCellWithIdentifier:@"MyCell"]; 

    if (cell==nil) { 
     cell = [[[CellHomeFeedViewController alloc] init] autorelease]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.backgroundColor = [UIColor clearColor]; 

     cell.lblUsername.textColor=[UIColor colorWithRed:0.0/255.0 green:176.0/255.0 blue:240.0/255.0 alpha:1.0]; 
     cell.lblTime.textColor=[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]; 
     cell.lblDetails.textColor=[UIColor colorWithRed:71.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]; 

     // Tap GestureRecognizer for User Image 
     UITapGestureRecognizer *UserImg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(UserNameORimageGesture:)]; 
     UserImg.delegate = self; 
     UserImg.numberOfTapsRequired = 1; 
     cell.imgUserPic.userInteractionEnabled = YES; 
     [cell.imgUserPic addGestureRecognizer:UserImg]; 

     // Tap GestureRecognizer for Name Label 
     UITapGestureRecognizer *NameLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(UserNameORimageGesture:)]; 
     NameLabel.delegate = self; 
     NameLabel.numberOfTapsRequired = 1; 
     cell.lblUsername.userInteractionEnabled = YES; 
     [cell.lblUsername addGestureRecognizer:NameLabel]; 

     // Tap GestureRecognizer for Time Label 
     UITapGestureRecognizer *TimeLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(UserNameORimageGesture:)]; 
     TimeLabel.delegate = self; 
     TimeLabel.numberOfTapsRequired = 1; 
     cell.lblTime.userInteractionEnabled = YES; 
     [cell.lblTime addGestureRecognizer:TimeLabel]; 

     UITapGestureRecognizer *lbltotalCmt = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lbltotalCmtPress:)]; 
     lbltotalCmt.delegate = self; 
     lbltotalCmt.numberOfTapsRequired = 1; 
     cell.lblTotalComment.userInteractionEnabled = YES; 
     [cell.lblTotalComment addGestureRecognizer:lbltotalCmt]; 
     cell.lblTotalComment.tag=indexPath.row; 

     UITapGestureRecognizer *lbltotalFav = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lbltotalFavPress:)]; 
     lbltotalFav.delegate = self; 
     lbltotalFav.numberOfTapsRequired = 1; 
     cell.lblTotalFavourite.userInteractionEnabled = YES; 
     [cell.lblTotalFavourite addGestureRecognizer:lbltotalFav]; 
     cell.lblTotalFavourite.tag=indexPath.row; 

     cell.imgUserPic.tag=indexPath.row; 
     cell.lblUsername.tag=indexPath.row; 
     cell.lblTime.tag=indexPath.row; 
     cell.BtnCmnt.tag=indexPath.row; 
     cell.BtnGraph.tag=indexPath.row; 
     cell.BtnStar.tag=indexPath.row; 
     cell.btnMore.tag=indexPath.row; 
     cell.BtnFollow.tag = indexPath.row; 

     [cell.BtnFollow addTarget:self action:@selector(btnFollowListPress:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.BtnCmnt addTarget:self action:@selector(BtnCmnt:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.BtnGraph addTarget:self action:@selector(BtnGraph:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.BtnStar addTarget:self action:@selector(BtnStar:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell.btnMore addTarget:self action:@selector(BtnMore:) forControlEvents:UIControlEventTouchUpInside]; 
    } 

    NSData *newdata = [[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"album_title"] dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; 
    NSString *mystring=[[NSString alloc] initWithData:newdata encoding:NSNonLossyASCIIStringEncoding]; 
    if (mystring.length > 200) { 
     NSRange range = NSMakeRange(0, 200); 
     mystring = [mystring substringWithRange:range]; 
    } 

    if (mystring.length > 0) { 
     cell.lblDetails.text = mystring; 
    } 
    cell.lblDetails.delegate = self; 

    cell.lblTotalFavourite.text = [NSString stringWithFormat:@"(%@)",[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"favourite_count"]]; 
    cell.lblTotalComment.text = [NSString stringWithFormat:@"(%@)",[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"comments_count"]]; 
    cell.lblTime.text = [[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"album_created"]; 
    cell.lblUsername.text = [[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"user_name"]; 
    [cell.imgUserPic sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",mainImageURL,[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"thum_image"]]] placeholderImage:[UIImage imageNamed:@"400_loading_img.png"]]; 

    if ([[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"favourite_status"] isEqualToString:@"0"]) { 
     [cell.BtnStar setImage:[UIImage imageNamed:@"home_fvrte_icon.png"] forState:UIControlStateNormal]; 
    } else { 
     [cell.BtnStar setImage:[UIImage imageNamed:@"home_fvrte_icon_on.png"] forState:UIControlStateNormal]; 
    } 

    if ([[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"contact_allowed"] isEqualToString:@"1"]) { 
     if ([[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"is_following"] isEqualToString:@"1"]) { 
      cell.boolCheck = NO; 
      cell.BtnFollow.hidden = YES; 
      [cell.BtnFollow setImage:[UIImage imageNamed:@"following_icon.png"] forState:UIControlStateNormal]; 
     } else { 
      cell.boolCheck = YES; 
      cell.BtnFollow.hidden = NO; 
      [cell.BtnFollow setImage:[UIImage imageNamed:@"hp_add_frnd_icon.png"] forState:UIControlStateNormal]; 
     } 
    } else { 
     cell.boolCheck = NO; 
     cell.BtnFollow.hidden = YES; 
    } 

    if ([[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"has_commented"] isEqualToString:@"1"]) { 
     [cell.BtnCmnt setImage:[UIImage imageNamed:@"home_comment_on.png"] forState:UIControlStateNormal]; 
    } else { 
     [cell.BtnCmnt setImage:[UIImage imageNamed:@"home_comment.png"] forState:UIControlStateNormal]; 
    } 

    if ([[[arrAllPost objectAtIndex:indexPath.row] objectForKey:@"album_photo"] count]>0) { 
     cell.boolPostType = YES; 
     cell.tblSlider.hidden = NO; 
     cell.tblSlider.tag = indexPath.row; 
     cell.tblSlider.delegate = self; 
     cell.tblSlider.dataSource = self; 
     [cell.tblSlider reloadData]; 
    } else { 
     cell.boolPostType = NO; 
     cell.tblSlider.hidden = YES; 
    } 

    return cell; 

Ниже код cutomcell:

> @implementation CellHomeFeedViewController @synthesize 
> imgUserPic,tblSlider; @synthesize 
> lblUsername,lblTime,lblDetails,lblTotalFavourite; @synthesize 
> BtnCmnt,BtnGraph,BtnStar,btnMore,imgClock,ViewBottom,BtnFollow,btnReadMore; 
> @synthesize lblTotalComment,boolCheck,boolPostType; 
> 
> - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 
>  self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier]; 
>  if (self) 
>  { 
>   appdelegate = (UBUBBLAppDelegate*)[UIApplication sharedApplication].delegate; 
>   
>   imgUserPic = [[UIImageView alloc] init]; 
>   [self.contentView addSubview:imgUserPic]; 
>   
>   lblUsername=[[UILabel alloc]init]; 
>   lblUsername.textColor=[UIColor colorWithRed:0.0/255.0 green:176.0/255.0 blue:240.0/255.0 alpha:1.0]; 
>   lblUsername.font= [UIFont fontWithName:@"calibri" size:14.0f]; 
>   [lblUsername setBackgroundColor:[UIColor clearColor]]; 
>   lblUsername.textAlignment = NSTextAlignmentLeft; 
>   [self.contentView addSubview:lblUsername]; 
>   
>   lblTime=[[UILabel alloc]init]; 
>   [lblTime setBackgroundColor:[UIColor clearColor]]; 
>   lblTime.font= [UIFont fontWithName:@"calibri" size:10.0f]; 
>   lblTime.textAlignment = NSTextAlignmentLeft; 
>   [self.contentView addSubview:lblTime]; 
>   
>   appdelegate.lblLinkColor = [UIColor colorWithRed:0.0/255.0 green:176.0/255.0 blue:240.0/255.0 alpha:1.0]; 
>   appdelegate.lblTxtColor = [UIColor darkGrayColor]; 
>   
>   lblDetails=[[KILabel alloc]init]; 
>   lblDetails.font= [UIFont fontWithName:@"calibri" size:14.0f]; 
>   [lblDetails setBackgroundColor:[UIColor clearColor]]; 
>   lblDetails.textAlignment = NSTextAlignmentLeft; 
>   lblDetails.numberOfLines = 50; 
>   lblDetails.textColor = [UIColor blackColor]; 
>   lblDetails.userInteractionEnabled = YES; 
>   [self.contentView addSubview:lblDetails]; 
>   
>   tblSlider=[[UITableView alloc] init]; 
>   tblSlider.showsHorizontalScrollIndicator = NO; 
>   tblSlider.showsVerticalScrollIndicator = NO; 
>   tblSlider.separatorStyle = UITableViewCellSeparatorStyleNone; 
>   tblSlider.transform = CGAffineTransformMakeRotation(-M_PI_2); 
>   [self.contentView addSubview:tblSlider]; 
>   
>   imgClock = [[UIImageView alloc] init]; 
>   imgClock.image = [UIImage imageNamed:@"home_clock_icon.png"]; 
>   [self.contentView addSubview:imgClock]; 
>   
>   ViewBottom = [[UIView alloc] init]; 
>   ViewBottom.backgroundColor = [UIColor clearColor]; 
>   [self.contentView addSubview:ViewBottom]; 
>   
>   btnMore = [UIButton buttonWithType:UIButtonTypeCustom]; 
>   [btnMore setImage:[UIImage imageNamed:@"home_more_icon.png"] forState:UIControlStateNormal]; 
>   [ViewBottom addSubview:btnMore]; 
>   
>   BtnCmnt = [UIButton buttonWithType:UIButtonTypeCustom]; 
>   [BtnCmnt setImage:[UIImage imageNamed:@"home_comment.png"] forState:UIControlStateNormal]; 
>   [ViewBottom addSubview:BtnCmnt]; 
>   
>   BtnStar = [UIButton buttonWithType:UIButtonTypeCustom]; 
>   [BtnStar setImage:[UIImage imageNamed:@"home_fvrte_icon_on.png"] forState:UIControlStateNormal]; 
>   [ViewBottom addSubview:BtnStar]; 
>   
>   BtnFollow = [UIButton buttonWithType:UIButtonTypeCustom]; 
>   [BtnFollow setImage:[UIImage imageNamed:@"following_icon.png"] forState:UIControlStateNormal]; 
>   [ViewBottom addSubview:BtnFollow]; 
>   
>   BtnGraph = [UIButton buttonWithType:UIButtonTypeCustom]; 
>   [BtnGraph setImage:[UIImage imageNamed:@"home_status_icon.png"] forState:UIControlStateNormal]; 
>   [ViewBottom addSubview:BtnGraph]; 
>   
>   lblTotalComment=[[UILabel alloc]init]; 
>   lblTotalComment.font= [UIFont fontWithName:@"calibri" size:12.0f]; 
>   [lblTotalComment setBackgroundColor:[UIColor clearColor]]; 
>   [lblTotalComment setTextColor:[UIColor darkGrayColor]]; 
>   [ViewBottom addSubview:lblTotalComment]; 
>   
>   lblTotalFavourite=[[UILabel alloc]init]; 
>   lblTotalFavourite.font= [UIFont fontWithName:@"calibri" size:12.0f]; 
>   [lblTotalFavourite setBackgroundColor:[UIColor clearColor]]; 
>   [lblTotalFavourite setTextColor:[UIColor darkGrayColor]]; 
>   [ViewBottom addSubview:lblTotalFavourite]; 
>   
>  } 
>  return self; } 
> 
> -(void)layoutSubviews { 
>  [super layoutSubviews]; 
>  
>  imgUserPic.frame = CGRectMake(5, 5, 36, 36); 
>  imgClock.frame = CGRectMake(47, 27, 11, 12); 
>  lblTime.frame = CGRectMake(61, 27, 260, 12); 
>  
>  NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
>  paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; 
>  paragraphStyle.alignment = NSTextAlignmentLeft; 
>  
>  CGSize labelSize; 
>  
>  NSDictionary * attributes = @{NSFontAttributeName : self.lblUsername.font, 
>         NSParagraphStyleAttributeName : paragraphStyle}; 
>  labelSize = [lblUsername.text boundingRectWithSize:(CGSize){250, 17000} 
>            options:NSStringDrawingUsesFontLeading | 
> NSStringDrawingUsesLineFragmentOrigin 
>           attributes:attributes context:nil].size; 
>  [lblUsername setFrame:CGRectMake(47, 7, 250, 18)]; 
>  
>  CGFloat yOffset = 45.0; 
>  NSDictionary * attributes1 = @{NSFontAttributeName : self.lblDetails.font, 
>         NSParagraphStyleAttributeName : paragraphStyle}; 
>  labelSize = [lblDetails.text boundingRectWithSize:(CGSize){305, 17000} 
>            options:NSStringDrawingUsesFontLeading | 
> NSStringDrawingUsesLineFragmentOrigin 
>           attributes:attributes1 context:nil].size; 
>  [lblDetails setFrame:CGRectMake(15, yOffset, 305, labelSize.height+30)]; 
>  
>  //btnReadMore.frame = CGRectMake(240, yOffset+labelSize.height-5, 80, 20); 
>  
>  if (boolPostType) { 
>   yOffset+=labelSize.height+20; 
>   tblSlider.frame = CGRectMake(0, yOffset+10, 320, 182); 
>   yOffset+=185; 
>   BtnGraph.hidden = NO; 
>   if (boolCheck) { 
>    BtnCmnt.frame = CGRectMake(1, 0, 40, 40); 
>    BtnGraph.frame = CGRectMake(75, 0, 50, 40); 
>    BtnStar.frame = CGRectMake(141, 0, 40, 40); 
>    lblTotalComment.frame = CGRectMake(35, 5, 40, 30); 
>    lblTotalFavourite.frame = CGRectMake(174, 5, 40, 30); 
>    btnMore.frame = CGRectMake(270, 0, 50, 40); 
>    BtnFollow.frame = CGRectMake(213, 0, 50, 40); 
>   } else { 
>    BtnCmnt.frame = CGRectMake(1, 0, 40, 40); 
>    BtnGraph.frame = CGRectMake(95, 0, 50, 40); 
>    BtnStar.frame = CGRectMake(186, 0, 40, 40); 
>    lblTotalComment.frame = CGRectMake(35, 5, 40, 30); 
>    lblTotalFavourite.frame = CGRectMake(219, 5, 40, 30); 
>    btnMore.frame = CGRectMake(270, 0, 50, 40); 
>   } 
>  } else { 
>   yOffset+=labelSize.height+10; 
>   BtnGraph.hidden = YES; 
>   if (boolCheck) { 
>    BtnCmnt.frame = CGRectMake(1, 0, 40, 40); 
>    BtnStar.frame = CGRectMake(97, 0, 40, 40); 
>    lblTotalComment.frame = CGRectMake(35, 5, 40, 30); 
>    lblTotalFavourite.frame = CGRectMake(130, 5, 40, 30); 
>    btnMore.frame = CGRectMake(270, 0, 50, 40); 
>    BtnFollow.frame = CGRectMake(195, 0, 50, 40); 
>   } else { 
>    BtnCmnt.frame = CGRectMake(1, 0, 40, 40); 
>    BtnStar.frame = CGRectMake(136, 3, 30, 30); 
>    lblTotalComment.frame = CGRectMake(35, 5, 40, 30); 
>    lblTotalFavourite.frame = CGRectMake(165, 10, 35, 15); 
>    btnMore.frame = CGRectMake(270, 0, 50, 40); 
>   } 
>  } 
> 
>  ViewBottom.frame = CGRectMake(0, yOffset+15, 320, 40); } 
> 
> -(CGFloat)requiredHieghtForCellInTableView:(UITableView *)tableView { 
>  NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
>  paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; 
>  paragraphStyle.alignment = NSTextAlignmentJustified; 
>  
>  CGSize labelSize; 
>  
>  CGFloat yOffset = 45.0; 
>  NSDictionary * attributes = @{NSFontAttributeName : self.lblDetails.font, 
>         NSParagraphStyleAttributeName :paragraphStyle}; 
>  labelSize = [lblDetails.text boundingRectWithSize:(CGSize){305, 17000} 
>            options:NSStringDrawingUsesFontLeading | 
> NSStringDrawingUsesLineFragmentOrigin 
>           attributes:attributes context:nil].size; 
>  
>  yOffset+=labelSize.height; 
>  
>  if (boolPostType) 
>   yOffset+=205; 
>  else 
>   yOffset+=10; 
>  
>  yOffset+=60; 
>  
>  return yOffset; } 
> 
> @end 
+0

TL, не прочитал (много). Тем не менее, я вижу преобразование 'NSData' в' NSString' в ячейке. Я не знаю, как ** большой ** эти данные (строка) на самом деле, но это, безусловно, повлияет на производительность. Может быть, только часть вашей проблемы, но все равно это повлияет. Почему бы не преобразовать «NSData» один раз и не сохранить строки в массиве? – n00bProgrammer

ответ

1

если (ячейка == ноль

Удалить это, если заявление и продолжить Эта строка вызывает. проблема

njoy кодировка

 Смежные вопросы

  • Нет связанных вопросов^_^