簡體   English   中英

使用Storyboard時不通過Storyboard推送ViewController

[英]Push a ViewController not through Storyboard while working with Storyboard

我在整個互聯網上搜索了我的問題,但顯然是愚蠢的發現了什么。

在我的應用中,我正在使用情節提要,並且大多數ViewController都以這種樣式加載(我正在使用導航控制器):

MyViewControllerClass *viewController = [storyboard instantiateViewControllerWithIdentifier:@"myViewController"];
[self.navigationController pushViewController:viewController animated:YES];

現在我的問題是:是否可以在不使用情節提要的情況下在代碼中推送VC? 就像在過去一樣,但這對我而言不再有效:

MyViewControllerClass *viewController = [[MyViewControllerClass alloc] init];
[self.navigationController pushViewController:viewController animated:YES];

請幫助我,我快瘋了。

提前致謝。

是的,您可以在不使用情節提要的情況下做到這一點,只需要在這樣的應用程序委托中添加導航控制器,即可正常工作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

    self.window.rootViewController=navigationController;

    [self.window makeKeyAndVisible];

    return YES;

}

您可以創建xib文件並將其推送。 沒有視覺就無法推動。

ViewControllernew* vv = (ViewControllernew*)[[[NSBundle mainBundle] loadNibNamed:@"ViewControllernew" owner:self options:nil] objectAtIndex:0];
[self.navigationController pushViewController:vv animated:YES];

可以確認它能正常工作。 如果viewController為nil,則Push將以這種方式起作用。 您的alloc初始化實際上創建了一個實例嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM