2012-12-04 97 views
0

我有一个tableViewtextFieldtextView在两个单元格中。而已。 和我在tableView:cellForRowAtIndexPath:中加入了它们。 我无法编辑内容! 可能触摸不通过文本字段和textView如何将UITextField或UITextView添加到UItableViewCell并编辑内容?

所有的解决方案都要求我使用带有自定义单元类的xib。

那么,我必须为两行tableView创建两个新类吗?

不能,我只是逃脱通过添加这些作为子视图正常细胞的contentView

其次,如果使用tableView该种类的布局是矫枉过正,

什么是我需要一个文本区域下方的textView矩形边框圆角,并与普通UIViews他们之间的分隔符的alternatve?

回答

0

你不需要去创建2个新类。添加它们可以做得很好,甚至可以在控制器中保留一个参考。

检查您的UITableView,UITableViewCellUITextFieldUITextView上的userInteractionEnabled。如果您禁用视图的用户交互,则每个子视图也会禁用其用户交互。如果你想禁用一行的选择,只需设置cell.selectionStyle = UITableViewCellSelectionStyleNone;

0

你不需要一个xib子类UITableViewCell。在这种情况下,添加到内容视图应该没问题,并且子类不是必需的。这也听起来像你不需要一个表视图。您可能需要的一个原因是如果您需要更多这些单元格,否则常规视图控制器可能更适合并更易于实现。

我使用Core Graphics在UIView对象上创建圆角,甚至添加阴影效果,但有一点学习曲线。你可以从网上搜索UIView圆角开始。

0

尝试使用此代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (indexPath.row == 0){ 
     UITextField *customField = [[UITextField alloc] initWithFrame:CGRectMake(60.0f, 10.0f, 400.0f, 60.0f)] 
     customField.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
     customField.delegate = self; 
     customField.adjustsFontSizeToFitWidth = NO; 
     customField.borderStyle = UITextBorderStyleNone; 
     customField.autocapitalizationType = UITextAutocapitalizationTypeNone; 
     customField.autocorrectionType = UITextAutocorrectionTypeNo; 
     customField.enablesReturnKeyAutomatically = YES; 
     customField.returnKeyType = UIReturnKeyDefault; 
     customField.keyboardType = UIKeyboardTypeDefault; 
     [cell addSubview:customField]; 

    } 


    if (indexPath.row == 1){ 
     UITextView *notes = [[UITextView alloc] init]; 
     notes.editable = YES; 
     notes.font = DEFAULT_FONT(16); 
     notes.text = infoNotesStr.text; 
     notes.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
     notes.backgroundColor = [UIColor blueColor]; 
     notes.delegate = self; 
     CALayer *layers = notes.layer; 
     layers.cornerRadius = 10.0f; 
     [cell addSubview:notes]; 

    } 

} 
相关问题