滚动时UITableView行抖动

时间:2016-02-12 10:12:23

标签: ios objective-c uitableview

  1. 在我的表格视图中,我使用自定义单元格
  2. 在每个部分中包含一行,每个部分包含标题。节标题增加或减少基于高度的动态文本。在那种情况下,当我滚动时,部分是抽搐。

    # pragma mark - UITableView Delegate methods
    
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
      return auctionResultAry.count;
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
      return 1;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell;
    if (auctionResultAry.count == 0) {
        cell = [self tableView:self.tableView EmptycellForRowAtIndexPath:indexPath];
     }
     else{
     cell = [self tableView:self.tableView latestofferscellForRowAtIndexPath:indexPath];
    self.tableView.scrollEnabled=YES;
    }
    return cell;
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView latestofferscellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
    static NSString *cellidentifier=@"Cell";
    
    subcell=(CTEAuctionBidNowTVCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
    
    
    
    if (subcell==nil)
    {
       subcell =(CTEAuctionBidNowTVCell *) [[[NSBundle mainBundle] loadNibNamed:@"CTEAuctionBidNowTVCell" owner:self options:nil]objectAtIndex:0];
    
      }
    
    
      subcell.event_auction_name.text=[NSString stringWithFormat:@"%@",[[auctionResultAry objectAtIndex:indexPath.section ]objectForKey:@"auction_title"]];
    
    subcell.selectionStyle=UITableViewCellSelectionStyleNone;
    return subcell;
     }
    
  3. 我在节标题

    中编写代码
      - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
      {
       UIView *headerView;
       headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 60)];
        headerView.backgroundColor = [UIColor lightGrayColor];
    
    
            UILabel *auctionIdLbl=[[UILabel alloc] initWithFrame:CGRectMake(headerView.frame.size.width-115, headerView.frame.origin.y+5, 110, 20)];
            auctionIdLbl.textColor =[UIColor blackColor];
            auctionIdLbl.textAlignment=NSTextAlignmentRight;
            auctionIdLbl.font=[UIFont fontWithName:@"Arial-BoldMT" size:13];
            auctionIdLbl.text = [NSString stringWithFormat:@"ID: %@",[[auctionResultAry objectAtIndex:section]objectForKey:@"auction_id"]];
            [headerView addSubview:auctionIdLbl];
    
        UILabel *titleLnbl = [[UILabel alloc]initWithFrame:CGRectMake(5, headerView.frame.origin.y+5, +headerView.frame.size.width-100, 150)];
        titleLnbl.textColor =[UIColor blackColor];
        titleLnbl.font=[UIFont fontWithName:@"Arial-BoldMT" size:13];
        titleLnbl.numberOfLines=0;
        titleLnbl.textAlignment=NSTextAlignmentLeft;
        titleLnbl.text = [NSString stringWithFormat:@"%@",[[auctionResultAry objectAtIndex:section]objectForKey:@"auction_title"]];
       CGSize size = [self getSizebasedOnText:titleLnbl];
       CGFloat titleLnblHght=size.height;
    
            CGRect updateLblHght= titleLnbl.frame;
            updateLblHght.size.height=titleLnblHght;
            titleLnbl.frame=updateLblHght;
        [headerView addSubview:titleLnbl];
    
        return headerView;
        }
    

1 个答案:

答案 0 :(得分:0)

由于uitableview中行高的变化。如果行高很大,则不常见。