【发布时间】:2011-08-21 05:49:10
【问题描述】:
我希望能够在通过键盘输入文本时以编程方式更新表格视图中某个部分的页脚标题。当我单击一个单元格以使其详细文本视图可编辑时会出现键盘,因此我想在不从数据源重新加载的情况下更新页脚标题。
事实上,如果我这样做了,键盘就会消失,所以这不是一种好的交互方式。我一直无法找到解决这个问题的好方法...有什么建议吗?
谢谢
【问题讨论】:
标签: iphone ios uitableview
我希望能够在通过键盘输入文本时以编程方式更新表格视图中某个部分的页脚标题。当我单击一个单元格以使其详细文本视图可编辑时会出现键盘,因此我想在不从数据源重新加载的情况下更新页脚标题。
事实上,如果我这样做了,键盘就会消失,所以这不是一种好的交互方式。我一直无法找到解决这个问题的好方法...有什么建议吗?
谢谢
【问题讨论】:
标签: iphone ios uitableview
如果你有分组表,你可以使用:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 17)]; //I'm not sure about the frame...
yourLabel.font = [UIFont systemFontOfSize:16];
yourLabel.shadowColor = [UIColor whiteColor];
yourLabel.shadowOffset = CGSizeMake(0, 1);
yourLabel.textAlignment = UITextAlignmentCenter;
yourLabel.textColor = RGB(76, 86, 108);
yourLabel.backgroundColor = [UIColor clearColor];
yourLabel.opaque = NO;
return yourLabel;
}
在您的 .h 文件中声明 yourLabel。然后,您可以通过
yourLabel.text = @"whatever you want";
请检查是否有效:)
【讨论】:
yourFrameCGRect 实例应该放入什么维度?
NSArray中放置标签,然后使用for循环。
CGRectMake(0, 0, 320, 17)。
UILabel 的autoresizingMask?
我知道我来晚了,但我发现你可以这样做:
[self.tableView beginUpdates];
[self.tableView footerViewForSection:section].textLabel.text = @"Whatever";
[[self.tableView footerViewForSection:section].textLabel sizeToFit];
[self.tableView endUpdates];
【讨论】:
对于第一部分(ziro)
[self.tableView footerViewForSection:0].textLabel.text = @"test";
【讨论】:
Mark Alldritt 的回答很好,但有时标签大小不正确。固定示例如下(对于部分 == 0):
[self.tableView beginUpdates];
UILabel *footerLabel = [self.tableView footerViewForSection:0].textLabel;
footerLabel.text = [self tableView:self.tableView titleForFooterInSection:0];
CGRect footerLabelFrame = footerLabel.frame;
footerLabelFrame.size.width = self.tableView.bounds.size.width;
footerLabel.frame = footerLabelFrame;
[self.tableView endUpdates];
【讨论】:
tableView.beginUpdates()
tableView.footerView(forSection: 0)?.textLabel?.text = "Text Here"
tableView.endUpdates()
【讨论】: