簡體   English   中英

如何在表視圖中獲取uitextfields的文本?

[英]How to get text of uitextfields in table view.?

如何在iOS5的TableView中獲取文本字段的值? 我已經嘗試過標簽,但無法正常工作。

可能您使用自定義單元格。 如果要在選擇單元格時獲取文本值(創建時或在xib文件中需要為UITextField設置標簽):

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITextField *textField = [[tableView cellForRowAtIndexPath:indexPath] viewWithTag:1];
    NSSTring *text = textField.text;
}

或者您可以在創建單元格時將委托設置為UITextField

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

設置代表

UITextField *textField = [cell viewWithTag:1];
textField.delegate = self;

您可以在此處了解有關UITextField委托的信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM