0

我正在为我的UITableViewController. 我正在创建的标题出现在当前标题下方,而不是替换它。如何更改此设置以便替换默认值或至少将我的新标题放在顶部而不是下方?

@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
... 
}



@implementation RootViewController

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

    return 40.0;

    }

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



  CGFloat height = [self tableView: tableView heightForHeaderInSection: section];

    UIView *header=[[UIView alloc]initWithFrame:CGRectMake(400,-10,300,height)];
    header.backgroundColor=[UIColor redColor];

    UILabel *headerLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,300,30)];
    headerLabel.backgroundColor=[UIColor redColor];
    headerLabel.shadowColor = [UIColor blackColor];
    headerLabel.shadowOffset = CGSizeMake(0,1);
    headerLabel.textColor = [UIColor whiteColor]; 
   headerLabel.text=@"Select";

    [header addSubview:headerLabel];

    [headerLabel release];
    return header;
}

红色是我的自定义,不会取代蓝色标题。 在此处输入图像描述

4

2 回答 2

1

“蓝色标题”是 NavigationBar 而不是 tableview 标题!

如果您不想要这个蓝色条,请选择您的导航控制器并将 TopBar 设置为无;o)

顶栏

于 2013-06-19T09:06:08.973 回答
0

那么它应该可以正常工作。代码不包含错误。你确定它不工作吗?

于 2013-06-19T08:42:02.137 回答