Editing a UITextField inside a UITableViewCell fails

前端 未结 7 1775
时光取名叫无心
时光取名叫无心 2020-12-04 11:24

In my application I have a UITextField inside a UITableViewCell. If I click inside the text field and add some text I find that if try to move the

7条回答
  •  暖寄归人
    2020-12-04 11:56

    The answer by Brian M. Criscuolo is the closest, however its still not quite right - in my usage of SDK2.2.1 I find that I have to do the following:

    To your UITableViewDelegate (which is often your UITableViewController) add both of the following:

    - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return NO;
    }
    

    and:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        return UITableViewCellEditingStyleNone;
    }
    

    and:

    - (void)viewDidLoad {
    [super viewDidLoad];
    
        // do any other customisation here
    self.uiTableView.editing = true;
    }
    

    If you don't put the top two delegate methods, the above will cause the delete icons next to each row, and the indentation of each row.

    You shouldn't need to do anything with textfield delegates as Brian indicated (unless you have multiple rows and you want to respond to a didSelectRowAtIndexPath: event - which you don't seem to get while in edit mode - then you will need to also do as he suggests).

    By the way - this seems fixed in SDK3.0 (although subject to change I guess)

提交回复
热议问题