我是新iPhone的发展。我已创建了一个视图控制器和我用分组的表图。现在我想以显示我的视图 - 控制与图像和标签头视图。请指导我,帮助我在这个问题上。

感谢。

有帮助吗?

解决方案

你的意思是一个headerView或sectionHeaderView?可以在viewDidLoad方法子视图添加到headerView:

- (void)viewDidLoad {
    [super viewDidLoad];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 225)];
    label.text = @"BlaBla";
    [self.tableHeaderView addSubview:label];
}

您指定的大小和与initWithFrame方法标签的位置,并作为子视图添加标签到tableHeaderView - 你可以用多个标签做到这一点。

如果你指的是sectionHeader你必须实现tableView:viewForHeaderInSection:方法,你必须创建一个新的观点,不同的子视图添加到它:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
    label.text = @"BlaBla";
    [view addSubview:label];
    [label release];

    return [view autorelease];
}

在这种情况下,还必须实现具有返回你在上述方法创建视图的高度的方法tableView:heightForHeaderInSection:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50.0f;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top