2012-12-04 141 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]; 

    } 

} 
相關問題