加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 嵌入式导航控制器

发布时间:2020-12-15 01:49:32 所属栏目:百科 来源:网络整理
导读:我刚刚将我的Xcode从4.2更新到4.3.3并且我一直遇到问题 是否可以在单个视图应用程序中添加导航控制器,因为当我尝试将一个导入控制器插入控制器时没有任何反应.我希望有两个视图控制器通过按钮连接到第二个控制器,导航栏连接到第一个视图控制器. 我想不出任何
我刚刚将我的Xcode从4.2更新到4.3.3并且我一直遇到问题
是否可以在单个视图应用程序中添加导航控制器,因为当我尝试将一个导入控制器插入控制器时没有任何反应.我希望有两个视图控制器通过按钮连接到第二个控制器,导航栏连接到第一个视图控制器.

我想不出任何其他方式连接视图控制器请帮帮我
有任何想法吗.

解决方法

>如果您不想添加导航控制器,则可以使用presentViewController在现有视图控制器之间切换,从第一个转换到第二个,并解除ViewControllerAnimated以返回.
>假设您正在使用NIB(否则您只是使用故事板的embed命令),如果您要添加与NIB一起使用的导航控制器,则可以相应地更改您的应用程序委托.

所以,你可能有一个应用程序委托,说:

//  AppDelegate.h

#import <UIKit/UIKit.h>

@class YourViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong,nonatomic) UIWindow *window;

@property (strong,nonatomic) YourViewController *viewController;

@end

更改此项以添加导航控制器(您可以在此处删除以前对主视图控制器的引用):

//  AppDelegate.h

#import <UIKit/UIKit.h>

//@class YourViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong,nonatomic) UIWindow *window;

//@property (strong,nonatomic) YourViewController *viewController;
@property (strong,nonatomic) UINavigationController *navigationController;

@end

然后,在你的app delegate的实现文件中,你有一个didFinishLaunchingWithOptions可能会说:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
    self.window.rootViewController = self.viewController;

    [self.window makeKeyAndVisible];
    return YES;
}

你可以改变它说:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    //self.viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
    //self.window.rootViewController = self.viewController;

    YourViewController *viewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = self.navigationController;

    [self.window makeKeyAndVisible];
    return YES;
}

完成后,您现在可以使用pushViewController从一个NIB视图控制器导航到另一个视图控制器,并使用popViewControllerAnimated返回.在你的viewDidLoad中你也可以使用self.title = @“我的标题”;命令控制视图导航栏中显示的内容.您可能还想更改NIB中的“顶栏”属性以包含导航栏模拟度量标准,以便您可以布局屏幕并很好地了解它的外观:

显然,如果你有一个非ARC项目,那些具有视图控制器的alloc / init的行也应该也有自动释放(当你查看你的app委托时这将是显而易见的).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读