在tableviewcontroller中增加了个UINavigationBar,但是总是跟着tableview一块滚动,怎么才能固定在屏幕的最上方,不跟着tableview一块滚动了
添加UINavigationBar的代码如下
- C/C++ code
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(buttonPress:)]; UINavigationItem* navItem = [[UINavigationItem alloc]init]; navItem.rightBarButtonItem = item; navItem.title = @"患者列表"; UINavigationBar *naviBar = [[UINavigationBar alloc]init]; naviBar.items = [NSArray arrayWithObject:navItem]; naviBar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0); [self.tableView addSubview:naviBar]; [navItem release]; [naviBar release];
------解决方案--------------------
你这个BAR 是直接加在tableview上的,当然滑动啊。
------解决方案--------------------
建议换一种实现方式,在UINavigationController上加一个UITableView。
------解决方案--------------------
1 你把self.tableview.center向下移动44个像素,正好是一个tablebar的高度;
2 创建一个tablebar,加在self.view上。
------解决方案--------------------