I am experimenting with putting a UITextField
inside a UITableViewCell
.
Now I got two working methods.
Using addSubview
method:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(150, 7, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell addSubview:textFieldView];
Using setAccessoryView
method:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell setAccessoryView:textFieldView];
In my opinion the setAccessoryView
result is better looking, since the alignment is done automatically.
But my question is: It it ok to put a UITextField
inside a AccessoryView
? Or is there a good reason why I shouldn't do it that way?