我创建了一个基于 View 的应用程序,并在 appdelegate .h 文件中创建了 UINavigationcontroller 对象并将其添加到窗口 subview 中。接下来,在应用程序中确实完成了启动,我已经分配并初始化了一个类,当应用程序首次启动且导航栏位于其顶部时,我希望看到该类。
这是我将类添加到导航栏的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:navController.view];
//test is the class that i want to be viewed first when the app launches first
test *t = [[test alloc]initWithNibName:@"test" bundle:nil];
[navController.view addSubview:t.view];
[window makeKeyAndVisible];
return YES;
}
但问题是我的测试类启动但它不显示导航栏。可能是什么问题?
最佳答案
使用这样的一些(添加这些行)
appDelegate.h
UINavigationController *navController
@property (nonatomic,retain) UINavigationController *navController;
并以 .m 为单位
test *t = [[test alloc]initWithNibName:@"test" bundle:nil];
self.navController=[[[UINavigationController alloc] initWithRootViewController:t] autorelease];
[window addSubview:self.navController.view];
[window makeKeyAndVisible];
它可以帮助你。
从其他 View 来看,您需要创建 appDelegate 类的对象,然后访问该类的导航 Controller
看这个
yourAppDelegateClass *objAppDelegate=(yourAppDelegateClass *)[[UIApplication sharedApplication] delegate];
现在推送 View
SecondView *s=[[[SecondView alloc] initWithNibName:@"yournibName" bundle:nil] autorelease];
[objAppDelegate.navController pushViewController:s animated:YES];
这个概念对你有帮助。
关于iphone - 如何在导航 Controller 上调用另一个类并将其添加到应用程序委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5813845/