iphone - 如何在导航 Controller 上调用另一个类并将其添加到应用程序委托(delegate)

标签 iphone objective-c navigationcontroller

我创建了一个基于 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/

相关文章:

iphone - AFNetworking - 在恢复下载文件之前检查下载的字节数?

iphone - 在 iPhone 上滚动时重复图像

ios - 不能用 `UIPageViewController` 刷 `UINavigationController`

ios - 如果使用 Cocoapods 和 use_frameworks!,我应该使用 Obj-C Bridging Header 吗?

ios - 推送 View Controller 中的内存泄漏

swift - 添加新的 View Controller B 并将其更改为初始 View Controller 后出现 "View Controller A unreachable because it has no entry points"错误

iphone - 当 super View 不同时,如何在 iphone 中为 View 的帧更改设置动画......?

objective-c - NSURLConnection 使用 ARC 发送同步请求

iOS 禁用 NavigationController 后退按钮的动画

iphone - 如何让 iPhone 4 LED 灯瞬间发光?