在不重新加载的情况下更新UITableView中的页脚标题
问题描述:
我希望能够以编程方式更新表格视图内部分的页脚标题,同时通过键盘输入文本。当我点击一个单元格以使其detailText视图可编辑时,键盘出现,所以我想更新页脚标题而不从数据源重新加载。在不重新加载的情况下更新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";
访问,请检查其是否正常工作:)
答
我知道我迟到了这个线程,但我发现,你可以简单地这样做:
[self.tableView beginUpdates];
[self.tableView footerViewForSection:section].textLabel.text = @"Whatever";
[[self.tableView footerViewForSection:section].textLabel sizeToFit];
[self.tableView endUpdates];
答
对于第一部分(齐罗)
[self.tableView footerViewForSection:0] = .textLabel.text @ “测试”;
答
马克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];
是的,它可能会工作。但是我将不得不处理大量的团体,所以对我来说处理所有不同的标签并不那么容易。我真的会试图以一种干净的方式去做... – marzapower 2011-05-08 19:25:05
顺便说一下,我应该在'yourFrame' CGRect实例中放入什么尺寸? – marzapower 2011-05-08 19:25:35
您可以在'NSArray'中放置标签,然后使用'for'循环。 – akashivskyy 2011-05-08 19:26:21