2017-06-29 90 views
0

我剛剛啓動了Xcode objective-c,現在我試圖創建一個帶有textfields的tableview來輸入。我研究過其他堆棧溢出問題,但很多都是在6-8年前,似乎有廣泛的答案和極其複雜的問題。有人可以幫助我瞭解如何在表格視圖中插入文本字段並提供一些建議。謝謝!在UITableview中添加UITextField基本信息

+0

只需通過故事板拖放uitextfield到'UITableViewCell'中即可。 – Maddy

回答

1

寫代碼的UITableView細胞

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)]; 
textField.clearsOnBeginEditing = NO; 
textField.textAlignment = UITextAlignmentRight; 
textField.delegate = self; 
[aCell.contentView addSubview:txt]; 
+0

ok現在就試試吧 –

1

你可以做到這一點,如下所示:

  1. 拖放到您的視圖
  2. 拖放一個UITableView拖放一個UITableViewCell成你的桌子。
  3. 拖放一個UITextField(或任何其他 UI組件,你需要)

我建議你請參見教程,像

1. https://videos.raywenderlich.com/courses/22-table-views-in-ios/lessons/8 2. https://www.appcoda.com/expandable-table-view/

他們有最好的教程與所有步驟,你可以輕鬆地做任何你想要的。

我希望它能幫助你。

謝謝。

+0

非常感謝,將查看教程出來 –

+0

我已經更新了正確的教程鏈接。同樣也適用於appcode鏈接。 –

+0

非常感謝很多 –

0

試試下面的代碼

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; 

    if (cell == nil) { 

     /* 
     * Actually create a new cell (with an identifier so that it can be dequeued). 
     */ 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"]; 

     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    } 

    /* 
    * Now that we have a cell we can configure it to display the data corresponding to 
    * this row/section 
    */ 

    UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(45, 30, 200, 40)]; 
    tf.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0]; 
    tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:25]; 
    tf.backgroundColor=[UIColor whiteColor]; 
    [email protected]"Hello World"; 
    [cell.contentView addSubview:tf]; 

    /* Now that the cell is configured we return it to the table view so that it can display it */ 

    return cell; 

} 
0

您可以創建自定義單元格。在其中添加文本字段並通過註冊筆尖或類在表中使用該文本字段。