无法为表视图控制器添加页眉和页脚

时间:2011-04-29 09:05:58

标签: objective-c cocoa-touch xcode ios4

@property(nonatomic,retain) UIView *tableHeaderView;  

// accessory view for above row content. default is nil. not to be confused with section header
@property(nonatomic,retain) UIView *tableFooterView;  

// accessory view below content. default is nil. not to be confused with section footer

1 个答案:

答案 0 :(得分:1)

我在页脚中添加了一个标签View根据您的要求进行内部编码 无需制作任何全局变量。

- (UIView *)tableView:(UITableView *)tbleView viewForFooterInSection:(NSInteger)section
    {
                UILabel *label;
            label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 30)]autorelease];
            [label setBackgroundColor:[UIColor clearColor]];
            label.textAlignment = UITextAlignmentCenter;
            [label setTextColor:[UIColor whiteColor]];
            [label setFont:[UIFont boldSystemFontOfSize:15.0]];
            [label setText:NSLocalizedString(@"Instructions Personal Profile",@"Instructions Personal Profile")];


        UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)]autorelease];
          [view setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 
         [view addSubview:label];
         return view;


}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
}

用于设置页脚高度和标题使用: -

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
}