2017-08-16 92 views
0

我有一個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單元格,而不會顯示在屏幕上。 –

回答

0

你應該有存儲文本在結束鍵入之後的任何數組變量(索引明智)中的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

調試代碼。檢查這個方法的調用與否。 –

相關問題