ios pushViewController 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6596059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:38:50  来源:igfitidea点击:

pushViewController not working

iphoneobjective-ciosuinavigationcontrollerpushviewcontroller

提问by Jos

I have an application which has a view called store. In this view there is a button which loads the DetailView. Problem is that this detailview doesn't load/show. This is the code I use:

我有一个应用程序,它有一个名为 store 的视图。在此视图中,有一个加载 DetailView 的按钮。问题是这个 detailview 没有加载/显示。这是我使用的代码:

-(void)knop:(id)sender{
    categoryView = [[CategoryView alloc] init];
    //show detail view using buttonDetail...
    [self.navigationController pushViewController:categoryView animated:YES];
    [categoryView release];
    NSLog(@"Button is working");
}

The log "Button is working" logs, so the pushViewController line is also triggered.

日志“Button is working”日志,所以 pushViewController 行也被触发。

categoryView is made in my .h file:

categoryView 是在我的 .h 文件中制作的:

 CategoryView IBOutlet *categoryView;
}
@property (nonatomic, retain) IBOutlet CategoryView *categoryView;

In the store.xib there is a UIViewController with an outlet linked to the categoryView outlet.

在 store.xib 中,有一个 UIViewController 和一个连接到 categoryView 插座的插座。

Somewhere else in my app this is working, and I can't seem to find out why this one isn't

在我的应用程序的其他地方这是有效的,我似乎无法找出为什么这个不

Any help would be appreciated! THNX

任何帮助,将不胜感激!THNX

采纳答案by Jos

I have found it. Since I was using a tabbar based app, I needed to change the store tab to Navigation Controller. When I changed it, it worked! Thanks for all your support!!!

我已经找到了。由于我使用的是基于标签栏的应用程序,因此我需要将商店标签更改为导航控制器。当我改变它时,它起作用了!感谢您的支持!!!

回答by Patrick

Did you assign the UINavigationController in your AppDelegate?

您是否在 AppDelegate 中分配了 UINavigationController?

@interface

@界面

@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

@implementation didFinishLaunchingWithOptions

@implementation didFinishLaunchingWithOptions

rootViewController = [[RootViewController alloc] initWithNibName:@"RootView" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];

pushViewController works fine then through the whole App.

pushViewController 工作正常,然后通过整个应用程序。

回答by bshirley

It sounds like

这听起来像

NSLog(@"nav controller = %@", self.navigationController); 

will show that navigationController is nil.

将显示 navigationController 为零。

I suggest creating a new project of navigation type and see how this should be setup.

我建议创建一个导航类型的新项目,看看应该如何设置。

回答by Thomas Nadin

If your view is nib based, you need to use:

如果您的视图基于笔尖,则需要使用:

categoryView = [[CategoryView alloc] initWithNibName:nibName bundle:nibBundle];

Hope this helps.

希望这可以帮助。