Son*_*ony 8 iphone uiviewcontroller uinavigationcontroller ios
我有一个带UIToolbar的UIViewController(在底部),我想在里面添加一个带UINavigationBar的UINavigationController.但是不显示UINavigationController.
MyViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
int toolBarHeight = 44;
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, [self.view bounds].size.height-toolBarHeight, [self.view bounds].size.width, toolBarHeight)];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil];
toolBar.items = @[button];
[self.view addSubview:toolBar];
MyNavigationController *myNav = [[MyNavigationController alloc] init];
[self addChildViewController:myNav];
}
Run Code Online (Sandbox Code Playgroud)
arc*_*ist 16
将视图控制器添加为子视图控制器是不够的.您还需要将导航控制器的视图添加为容器视图控制器视图的子视图.
[myNav willMoveToParentViewController:self];
myNav.view.frame = navFrame; //Set a frame or constraints
[self.view addSubview:myNav.view];
[self addChildViewController:myNav];
[myNav didMoveToParentViewController:self];
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅View Controller编程指南.
| 归档时间: |
|
| 查看次数: |
12542 次 |
| 最近记录: |