我正在尝试以编程方式将navigationBar添加到tableViewController:
当我来自 PUSH Segue时,构建器会添加一个带有导航项的导航栏,就像我想要的那样。
但问题是,当我来到 MODAL Segue时,我尝试添加一个代码如下的栏:
UINavigationBar *naviBarObj = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, -260, 320, 44)];
[self.view addSubview:naviBarObj];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonPressed)];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonPressed)];
UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
navigItem.rightBarButtonItem = doneItem;
navigItem.leftBarButtonItem = cancelItem;
naviBarObj.items = [NSArray arrayWithObjects: navigItem,nil];
....
- (void) cancelButtonPressed { }
- (void) doneButtonPressed { }
但没有出现......没有顶栏。
答案 0 :(得分:4)
naviBarObj的帧ypoint是-260,也许这没有任何结果。