如何通过单击按钮来获取tableview单元格中textfield的值?

问题描述:

我有一个tableview用户进入他的社交媒体个人资料网址。我想通过点击一个按钮来获得该文本框的值。 tableview是动态的。我附上了截图供参考。我正在使用Objective C来构建一个iOs应用程序,我对此很陌生。有关如何做到这一点的任何建议?提前致谢。 !如何通过单击按钮来获取tableview单元格中textfield的值?

[这是在细胞文本框]

我曾经尝试这样做的实现代码如下:

NSMutableArray *Array = [NSMutableArray array]; 

for (int i=0; i < getMYurl.count; i++){ 

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow: i inSection: 0]; 

    SHOWURLTableViewCell *cellS = [table cellForRowAtIndexPath:indexPath]; 

    NSMutableDictionary *Dict = [NSMutableDictionary dictionary]; 

    UITextField *TextName= (UITextField*)[cellS.contentView viewWithTag:indexPath.row]; 
} 

而且我的cellForRowAtIndexPath方法:

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cellS = (SHOWURLTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"cell"]; 
// cellS.labelDesc.text = mergeName; 


    NSString *urlText = [[getMYurl valueForKey:@"url"]objectAtIndex:indexPath.row]; 
    cellS.labelUrl.text = urlText; 

    NSString *urlName = [[getMYurl valueForKey:@"url_name"]objectAtIndex:indexPath.row]; 

// [urlMap setValue:mergeName forKey:urlText]; 

    cellS.urlNameET.tag = 100; 
} 
+0

的NSMutableArray *阵列= [NSMutableArray的数组];对于(int i = 0; i

+0

显示您的cellforRow方法 –

+0

结束输入后,您应该必须将textfiled的文本存储在任何数组变量(索引明智)中。因为tableview会破坏tableview单元格,而不会显示在屏幕上。 –

你应该有存储文本在结束键入之后的任何数组变量(索引明智)中的textfiled。因为tableview会破坏tableview单元格,而不会显示在屏幕上。

- (void)textFieldDidEndEditing:(UITextField *)textField{  
      UITableViewCell *cell = (UITableViewCell*) textField.superview.superview; 
      NSIndexPath *txtIndPath = [self.tblPendingDeliveryData indexPathForCell:cell]; 

      [myMutableArray insertObject:textField.text atIndex:txtIndPath.row]; 
    } 

不要忘记设置委托的TextField

+0

我在cellForRowAt方法的cell.textfield上设置了代理自身,并使用了你的方法,但数组是空的。 –

+0

如果已解决您的问题,请将其标记为正确答案。 –

+0

调试代码。检查这个方法的调用与否。 –