我只想设置一个navigationController
,其中view
位于同一个xib文件中。
xib结构
File's Owner
navigationController
- > Navigation Controller
First Responder
Navigation Controller
navigationController
- > File's Owner
view
- > Scroll View
Scroll View
view
- > Navigation Controller
·H
@interface WannaBeNavController : UINavigationController <UINavigationControllerDelegate> {
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end
的.m
#import "WannaBeNavController.h"
@implementation WannaBeNavController
@synthesize navigationController;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController = navigationController;
//[self setNavigationController:navigationController];
//[navigationController setView:self.view];
@end
我尝试了许多没有成功的事情。我看到的只是空白navigationController
。
答案 0 :(得分:1)
您正在将navigationController分配给自己,可能是nil
。
我只是创建一个普通的ViewController(h,m,xib),没有任何指向NavigtaionController的链接(因此它也可以在基于导航的应用程序中重复使用;))。 NavigationController本身将设置该viewcontroller的navigationController属性。
在代码中,你写的是:
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController"];
UINavigationController *navContr = [[UINavigationController alloc] initWithRootViewController:myVC];
[myVC release];
//[window addSubView: navContr.view]; // or sth similar
window.rootViewController = navContr; // thanks to Paul Lynch for that line of code
修改强>:
如果是tabbarcontroller,那么只需编写代码:
MyViewController1 *myVC1 = [[MyViewController alloc] initWithNibName:@"MyViewController"];
MyViewController2 *myVC2 = [[MyViewController2 alloc] initWithNibName:@"MyViewController2"];
//...
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myVC1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:myVC2];
//...
UITabBarController *tabBarContr = [[UITabBarController alloc]init];
[tabBarContr setViewControllers:[NSArray arrayWithObjects:nav1,nav2,nil] animated:NO];
window.rootViewController = tabBarContr;
[myVC1 release];
[myVC2 release];
[nav1 release];
[nav2 release];
[tabBarContr release];
答案 1 :(得分:0)
我知道这可以通过多个文件或controller
xib
window
来实现,但似乎不是使用只有三个文件(h,m和xib)。
所以这就是我做的事情:
UIViewController
代替UINavigationController
UINavigationBar
。UIScrollView
UINavigationBar
UIScrollView
属性检查器中启用(选中)垂直弹跳。UIScrollView
似乎位于UINavigationBar
下方。我不确定如何完成这一步,但是当我弄清楚时,我会回复说明。