iphone - TableCell 中的 UITextView,如何为通用应用程序设置正确的宽度

标签 iphone ipad uitableview uitextview universal

我在 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/

相关文章:

ios - 对于以编程方式创建其所有内容的 UITableViewCell,我应该使用哪些初始化程序/方法?

iphone - ViewDidLoad 方法不保留变量?

iphone - MKReverseGeocoder 服务器返回错误 : 503

iphone - 链接到应用程序商店进行更新 - iPhone 不能在 iPad 上使用吗?

ios - 在 iOS 中访问用户联系人的问题

iphone - Cell TextLabel 多行不再工作

iphone - 在 Objective-C 中搜索字符串的最快方法是什么?

ios - 在 IOS 中动态添加新标签

ipad - 如何添加一个图片库以在reveal.js 的幻灯片上滑动?

iOS - 移动 View 时界面元素重叠