0

I have a table view. There is a custom table view cell on the table view. TableViewCell has a label and a text field. 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. Kindly give some suggestions to achieve the required thing correctly.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Prez
  • 227
  • 3
  • 12
  • First google it, Already many answers are available. – dahiya_boy May 05 '17 at 12:39
  • How are you populating the textfields in your tableview? – iPeter May 05 '17 at 12:43
  • You can set one flag to identify it's call of action for clearing the textfields. reload the tableview. It's simple soultion. If you don't want to referesh whole data, get all textfield reference and loop to clear them all – Sivajee Battina May 05 '17 at 12:43
  • 1
    Possible duplicate of [Get button click inside UI table view cell](http://stackoverflow.com/questions/20655060/get-button-click-inside-ui-table-view-cell) – dahiya_boy May 05 '17 at 12:46

1 Answers1

0

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 = @"":
    }
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84