2012-02-10 117 views
0

我在我的应用程序中有UITableView &通常创建tableview单元格并创建任何类文件。 在我的表单元格中,我添加了UITextview,因此我的UITableView是“无法顺利滚动”。 之后我评论textview代码或用textfield /标签替换textview然后tableview滚动应该平稳。UITableview不能顺利滚动

有谁能告诉我为什么会发生这种情况? 在此先感谢。

下面是我现在在表中增加的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]; 

     } 
    } 
+0

是什么txtShout ..? – vishy 2012-02-10 08:01:21

+0

你使用单元格重用吗?粘贴细胞生成代码在这里。 – NeverBe 2012-02-10 08:07:26

+0

@NeverBe:发布了我的手机代码... – niks 2012-02-10 11:41:48

回答

4
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]; 
+0

+1:viewWithTag的使用不错 – 2012-02-10 11:34:53

+0

@Sanjeev:太棒了! ,你的解决方案就像魅力一样......帮助我解决了我的问题...... – niks 2012-02-10 12:20:12

+0

@niks:那么你真的应该接受Sanjeev的答案 - 点击旁边的复选标记。 – 2012-02-10 12:37:17