将UITextField放在UITableViewCell的AccessoryView中 [英] Put a UITextField inside a UITableViewCell's AccessoryView
问题描述
我正在尝试将UITextField
放在UITableViewCell
中.
I am experimenting with putting a UITextField
inside a UITableViewCell
.
现在我有两种工作方法.
Now I got two working methods.
使用addSubview
方法:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(150, 7, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell addSubview:textFieldView];
使用setAccessoryView
方法:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
UITextField *textFieldView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
[textFieldView setPlaceholder:@"Placeholder"];
[cell setAccessoryView:textFieldView];
我认为setAccessoryView
结果看起来更好,因为对齐是自动完成的.
In my opinion the setAccessoryView
result is better looking, since the alignment is done automatically.
但是我的问题是:可以将UITextField
放在AccessoryView
里面吗?还是有一个很好的理由为什么我不应该那样做?
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?
推荐答案
苹果对此没有任何限制,但主要目的是在UITableViewCell
类中添加accessoryView
属性,以用作控件,通常用作控件,位于单元格的右侧(正常状态).
There is no any restriction on it by apple, but main intention to add accessoryView
property in UITableViewCell
class, to be used, typically as a control, on the right side of the cell (normal state).
以下句子摘自苹果文档:
如果此属性的值不为nil,则UITableViewCell类在表视图的正常(默认)enter code here
状态下将给定视图用于附件视图;它忽略accessoryType
属性的值. 提供的附件视图可以是框架提供的控件或标签,也可以是自定义视图.附件视图显示在单元格的右侧.
If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) enter code here
state; it ignores the value of the accessoryType
property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the right side of the cell.
根据此语句,您可以提供UITextField
(框架提供的控件)作为accessoryView
.
According to this statement you can provideUITextField
(framework-provided control) as accessoryView
.
这篇关于将UITextField放在UITableViewCell的AccessoryView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!