我在 tableView 单元格内使用 UITextView 来编辑文本。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITextField *textName = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 270, 24)];
[cell addSubview:textName];
[textName release];
}
这可行,但在 iPad 上运行时不正确。
我尝试使用以下方法确定单元格的宽度 cell.contentView.frame.size.width
但是对于 iPhone 和 iPad 总是返回 320.0
在 iPad 上,横向模式下单元格的宽度不应该更大吗?
特奥
最佳答案
理想情况下,您可以创建一个自定义 UITableViewCell
并在 layoutSubviews
中调整控件大小/位置。
如果您要在tableView:cellForRowAtIndexPath:
中添加控件,那么您可以从tableView本身获取宽度:
UITextField *textName = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width-50, 24)];
关于iphone - TableCell 中的 UITextView,如何为通用应用程序设置正确的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5264372/