简体   繁体   English

在按钮上单击清除表视图中驻留的所有文本字段的文本

[英]On button click clear text of all the textfields residing in tableview

I have a table view. 我有一张桌子。 There is a custom table view cell on the table view. 表格视图上有一个自定义表格视图单元。 TableViewCell has a label and a text field. TableViewCell具有标签和文本字段。 There is a button on the view controller outside the table view. 表格视图之外的视图控制器上有一个按钮。 On click of that button I want to remove the text of all textfields in the table view. 单击该按钮后,我要删除表格视图中所有文本字段的文本。 I am trying the following code: 我正在尝试以下代码:

- (IBAction)clear:(id)sender {
    detail.textfield.text=@""; 
}

Only the last cell's textfield.text gets cleared. 仅最后一个单元格的textfield.text被清除。 Kindly give some suggestions to achieve the required thing correctly. 请提出一些建议以正确实现所需的东西。

You need to empty all textfield as below : 您需要清空所有文本字段,如下所示:

- (IBAction)clickFavourite:(id)sender {

    for (int i = 0; i< arrDatasource.count; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UITableViewCell *cell = [tblViewDetail cellForRowAtIndexPath:indexPath]; // change with your cell's class
        cell.textField.text = @"":
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM