3

Same as Adding the "Clear" Button to an iPhone UITextField but that one is old. I tried

myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;

but nothing is happening. What could be preventing it?

Community
  • 1
  • 1
4thSpace
  • 43,672
  • 97
  • 296
  • 475
  • Stupid questions, since you haven't had an answer and I don't have a general answer: 1) have you tried it on a brand new UITextField? 2) a brand new UITextField in a fresh project? – mph Mar 18 '09 at 04:34
  • >since you haven't had an answer< My first time asking the question. Referenced question has a solution. Solution did not work for me. 1.) yes 2.) yes – 4thSpace Mar 18 '09 at 04:58
  • I meant my questions were stupid -- sorry. Just wanted to make sure you'd done the basics, since I had nothing of more value to offer... – mph Mar 18 '09 at 05:08
  • 1
    Got the fix - textfield was in tablecell, which was loaded via nib. Needed to put the above code where the cell is created. – 4thSpace Mar 18 '09 at 05:15
  • Cool! You should post the answer and mark it accepted ;) – mph Mar 18 '09 at 05:25

2 Answers2

5

In cellForRowAtIndex, the fix looks like this in my case:

cell = [tableView dequeueReusableCellWithIdentifier:@"CellNameIdentifier"];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CellName" owner:self options:nil];
        cell = cellName;
        [cellName setAccessoryType:UITableViewCellAccessoryNone];
        //textfield in inside cellName
        textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
    }
4thSpace
  • 43,672
  • 97
  • 296
  • 475
0

In some situations the UITextField height and alignment can cause the clear button to be hidden below the cell even though your text input displays fine.

Double check your height or try this :

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Stephan
  • 41,764
  • 65
  • 238
  • 329
alexw
  • 3
  • 2