2013-12-22 37 views
1

我對如何在UITableView中引用文本字段的文本感到非常困惑。我在tableview中有5行沒有文本加載,用戶輸入文本然後保存爲設置。我試圖讓數組_textBox1Contents和_textBox2Contents包含5個textBox1和textBox2文本域中的用戶輸入文本。如何引用特定單元格的文本字段以便使用NSUserDefaults將它們發送到應用程序的其他部分?如何在UITableView的單元格中引用文本字段的文本

在此先感謝。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TableCell"; 
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 

    long row = [indexPath row]; 

    cell.image.image = [UIImage imageNamed:_image[row]]; 
    cell.titleLabel.text = _Title[row]; 
    cell.textbox1.placeholder = _textBox1[row]; 
    cell.textbox2.placeholder = _textBox2[row]; 
    cell.colon.text = _colon[row]; 

    cell.textbox1.delegate = self; 
    cell.textbox2.delegate = self; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    _textBox1Contents = @[@"", 
          @"", 
          @"", 
          @"", 
          @"",]; 

    _textBox2Contents = @[@"", 
          @"", 
          @"", 
          @"", 
          @"",]; 

    return cell; 
} 
+0

使用性能。 – 2013-12-22 10:26:29

回答

1

給你的UITextField一個標籤(讓我們說100)。然後,在你的cellForRowAtIndexPath

UITextField *textField = (UITextField *)[cell viewWithTag:100]; 
textField.text = [NSString stringWithFormat:@"%d",indexPath.row]; 
1

您可以「保存」按鈕,例如添加和執行相應的回調爲:在自定義單元格類

- (IBAction)saveClicked:(id)sender { 
    for (int i = 0; i < _tableView.numberOfSections; i++) { 
     for (int j = 0; j < [_tableView numberOfRowsInSection:i]; j++) { 
      NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:j inSection:i]; 
      TableCell *currentCell = (TableCell *)[_tableView cellForRowAtIndexPath:currentIndexPath]; 
      // Get text field and store. 
     } 
    } 
相關問題