【问题标题】:UILabel in header of UITableView in objective c目标c中UITableView标题中的UILabel
【发布时间】:2012-01-19 02:37:21
【问题描述】:
我正在制作一个 iPad 应用程序,其中有一个分组的 TableView,其中包含各个部分的标题。
我想在表格视图的标题中添加四个标签
四个标签的文本分别是“company”、“current”、“prev close”、“change”
或
我不想在标题中添加四个标签,而是添加四个文本“公司”、“当前”、“上一个关闭”、“更改”
我该怎么办?
请帮助和建议。
谢谢。
【问题讨论】:
标签:
iphone
ipad
uitableview
header
uilabel
【解决方案1】:
有一个 UITableView 的委托方法,用于自定义 Header 的视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,40)];
UILabel *objLabel = [[UILabel alloc] initWiThFrame:CGRectMake(0,0,320,40)];
objLabel.text = @"Post";
[headerView addSubview:objLabel]; //Similarly You can Add any UI Component on header
[objLabel release];
return [headerView autorelease];
}
【解决方案2】:
如果您想在部分标题中将 Company、Current、prev next 显示为文本,则
只需将文本附加到单个字符串中并在以下委托方法中返回此值。
(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
希望这会有所帮助。
【解决方案3】:
你可以实现- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section,你可以为每个标题返回你想要的任何视图