[IOS]关于在UIViewController页面添加UINavigationBar的方法



//解决问题的关键就下面的这段代码

UIView *headerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 44)];
self.tableView.tableHeaderView = headerView;
[headerView release];
//加了上面的代码之后tabview就向下移了44个像素,那刚好放上navbar
CGRect aScreenRect = [[UIScreen mainScreen] bounds];

//创建navbar
UINavigationBar *nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, aScreenRect.size.width, 44)];
//创建navbaritem
UINavigationItem *NavTitle = [[UINavigationItem alloc] initWithTitle:@"详细介绍"];

[nav pushNavigationItem:NavTitle animated:YES];

[self.view addSubview:nav];

//创建barbutton 创建系统样式的
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(navBackBt:)];

//设置barbutton
NavTitle.leftBarButtonItem = item;
[nav setItems:[NSArray arrayWithObject:NavTitle]];

[item release];
[NavTitle release];
[nav release];

这样就OK了

猜你喜欢

转载自iaiai.iteye.com/blog/1745897