如何向UITextField添加清除按钮?

时间:2009-03-18 03:36:58

标签: iphone cocoa-touch uitextfield

Adding the "Clear" Button to an iPhone UITextField相同,但那个是旧的。我试过了

myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;

但没有发生任何事情。什么可能阻止它?

2 个答案:

答案 0 :(得分: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;
    }

答案 1 :(得分:0)

在某些情况下,即使文本输入显示正常,UITextField高度和对齐也可以使清除按钮隐藏在单元格下方。

仔细检查你的身高或试试这个:

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
相关问题