【问题标题】:UITableview not scrolling smoothlyUITableview 滚动不顺畅
【发布时间】:2012-02-10 07:45:36
【问题描述】:

我的应用程序中有 UITableView 并且在创建任何类文件时通常创建了 tableview 单元格。 在我的表格单元格中,我添加了 UITextview,因为我的 UITableView 是“not scrolling smoothing”。 在我注释 textview 代码或将 textview 替换为 textfield/Label 之后,tableview 会尽可能顺畅地滚动。

谁能告诉我为什么会这样? 提前致谢。

这是我在表格中添加 textview 的方式:

    UITextView *txtview = [[UITextView alloc]
    initWithFrame:CGRectMake(93.0,36.0,190.0,94.0)];            
    txtview.backgroundColor = [UIColor clearColor];
    txtview.text = [NSString stringWithFormat:@"%@",strText];
    txtview.contentInset = UIEdgeInsetsMake(5 ,0 ,0 ,0); 
    txtview.textColor = [UIColor colorWithRed:221.0/255.0 green:249.0/255.0
    blue:250.0/255.0 alpha:1.0];   
    [cell.contentView addSubview:txtview];
    [txtview release];

这是我的细胞生成代码:

    UITableViewCell *cell = [tableView
                            dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) 
        cell =[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 
              reuseIdentifier:CellIdentifier]autorelease];
    else
    {
      NSArray *arraySubviews = [cell.contentView subviews];

        for (UIView *views in arraySubviews)
        {
            [views removeFromSuperview];

        }
    }

【问题讨论】:

  • 你使用单元格复用吗?在此处粘贴单元生成代码。
  • @NeverBe :已经发布了我的细胞生成代码....
  • @vishy:txtShout 是我的错误...更新了我的代码...

标签: objective-c ios uitableview uitextview


【解决方案1】:
cell =(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];  

        if (nil ==cell) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];    
            UITextView *txtview = [[UITextView alloc]
                                   initWithFrame:CGRectMake(93.0,36.0,190.0,94.0)];            
            txtview.backgroundColor = [UIColor clearColor];
            txtview.tag = 15;

            txtview.contentInset = UIEdgeInsetsMake(5 ,0 ,0 ,0); 
            txtview.textColor = [UIColor colorWithRed:221.0/255.0 green:249.0/255.0
                                                 blue:250.0/255.0 alpha:1.0];   
            [cell.contentView addSubview:txtShout];
            [txtview release];
        }
        UITextView *txtview = (UITextView*)[cell.contentView viewWithTag:15];
        txtview.text = [NSString stringWithFormat:@"%@",strText];

【讨论】:

  • @Sanjeev:太棒了!!!,你的解决方案很有魅力......帮助我解决了我的问题......
猜你喜欢
  • 2014-12-06
  • 2011-11-06
  • 2012-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多