【发布时间】:2013-02-25 22:27:56
【问题描述】:
我想知道使 UITextField 适合 UITableView 单元格的最佳方法是什么。
我以前用过这个方法:
@implementation UITextField (custom)
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.origin.x + 0, bounds.origin.y + 10,
bounds.size.width - 30, bounds.size.height - 16);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
@end
但这会导致一个问题:
Category is implementing a method which will also be implemented by its primary class
虽然我已经看到了隐藏这些警告的方法,但感觉这更像是一种 hack,而不是正确的方法。
使 UItextField 适合单元格的最佳方法是什么。这是我的领域:
// Username field
usernameField = [[UITextField alloc] initWithFrame:(CGRectMake(10, 0, 300, 43))];
usernameField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
像这样输入到单元格中:
if (indexPath.row == 0) {
[cell.contentView addSubview:usernameField];
}
图片:
【问题讨论】:
标签: ios ios5 uitableview uitextfield