【发布时间】:2011-08-28 17:36:53
【问题描述】:
我有一个 UITableViewController 子类用于输入我的应用程序的设置。我将自定义按钮添加到表页脚,方法是将它们添加到我在调用 tableView:viewForFooterInSection: 时返回的视图中。
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
CGRect viewRect = self.view.bounds;
float height = _settings.isNew ? 50.0 : 110.0;
float margin = (viewRect.size.width > 480.0) ? 44.0 : 10.0;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewRect.size.width, height)];
GradientButton* button = [[GradientButton alloc] initWithFrame:CGRectMake(margin, 5, viewRect.size.width - margin * 2, 44)];
[view addSubview:button];
[button addTarget:self action:@selector(testConnectionClicked:) forControlEvents:UIControlEventTouchUpInside];
[button release];
if (!_settings.isNew)
{
// I add another button
}
return [view autorelease];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return _settings.isNew ? 50 : 110;
}
从 UITableViewController 子类化的重点是避免在键盘出现时让单元格滚动到视图中的问题。
这基本上可以正常工作,但是当编辑移动到最后一个单元格时,它似乎试图将表格页脚滚动到视图中。这意味着当在 iPhone 上以横向视图时,它实际上会将编辑文本字段滚动到视图之外。
【问题讨论】:
标签: iphone ios uitableview