如何向UITextField添加清除按钮?

4th*_*ace 3 iphone cocoa-touch uitextfield

将"清除"按钮添加到iPhone UITextField相同,但那个是旧的.我试过了

myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
Run Code Online (Sandbox Code Playgroud)

但什么也没发生.什么可能阻止它?

4th*_*ace 5

在cellForRowAtIndex中,修复在我的情况下看起来像这样:

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;
    }
Run Code Online (Sandbox Code Playgroud)