xcode IOS 切换视图和故事板不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8308732/
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-09-14 22:35:36  来源:igfitidea点击:

IOS Switch view and storyboard not works

iosxcodeuiviewcontrollerstoryboardnslog

提问by mudlee

I have a problem with switching views. I'm using a simulator with xcode 4.2

我在切换视图时遇到问题。我正在使用带有 xcode 4.2 的模拟器

Storyboard contains:

故事板包含:

  • NavigationController(initial view controller)
  • UIViewControllerwhich has relationship with the navigation controller
  • UIViewController(paired with my custom class: ViewEntryImageController) which hasn't got any relationship. Contains a button, a bottom toolbar with some toolbar button.
  • NavigationController(初始视图控制器)
  • UIViewController与导航控制器有关系
  • UIViewController(与我的自定义类配对:)ViewEntryImageController没有任何关系。包含一个按钮,一个带有一些工具栏按钮的底部工具栏。

User come into the UIViewController, where he can see a ScrollViewand in ScrollViewsome images.

用户进入UIViewController,在那里他可以看到一些图像中的ScrollViewScrollView

Images has a gesture:

图像有一个手势:

    UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(openEntryImage)];
    [image addGestureRecognizer:recognizer];
    [recognizer release];

The openEntryImage function:

openEntryImage 函数:

(IBAction)openEntryImage
{
    ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:nil bundle:nil];
    controller.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:controller animated:YES];
    [controller release];
}

When I try to tap the image, the openEntryImageworks as well (the effect is correct), but I don't see my ViewEntryImageControllerview and my buttons, I'm only see a black window.

当我尝试点击图像时,openEntryImage效果也很好(效果是正确的),但是我看不到我的ViewEntryImageController视图和按钮,我只能看到一个黑色窗口。

I try to put a NSLogline into the ViewEntryImageControllerviewDidLoadfunction, and it works, so what is the black window and where is my view controller?

我尝试将NSLog行放入该ViewEntryImageControllerviewDidLoad函数中,并且可以正常工作,那么黑色窗口是什么,我的视图控制器在哪里?

When I try to use pushViewController, on the new view I found a navigation toolbar with a back button, but no other controls.

当我尝试使用 时pushViewController,在新视图上我发现了一个带有后退按钮的导航工具栏,但没有其他控件。

I tried another version, I created a UIViewControllerclass, but now with a xibfile. I used it instead of ViewEntryImageControllerand it works. Why? I want to use this controller in storyboard too.

我尝试了另一个版本,我创建了一个UIViewController类,但现在使用了一个xib文件。我用它代替了ViewEntryImageController它,它起作用了。为什么?我也想在故事板中使用这个控制器。

采纳答案by Tom van der Woerdt

Try it like this :

像这样尝试:

ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:@"ViewEntryImageController" bundle:nil];

If you don't use .nib names but rather use storyboards, it's a bit harder. Create a segue from the controller to the ViewEntryImageController controller by holding ctrl and dragging from one view to the other. Click this segue and give it an identifier.

如果你不使用 .nib 名称而是使用故事板,那就有点难了。通过按住 ctrl 并从一个视图拖动到另一个视图,创建从控制器到 ViewEntryImageController 控制器的转场。单击此 segue 并为其指定标识符。

Then use the [self performSegue:@"identifier"];function to present the next view.

然后使用该[self performSegue:@"identifier"];功能呈现下一个视图。

回答by Dennis Bliefernicht

The ViewEntryImageControllerclass by itself has no information about how to build the dialog. But you can instantiate your view controller on your own from the storyboard:

ViewEntryImageController本身类有没有关于如何建立对话的信息。但是你可以从故事板中自己实例化你的视图控制器:

UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"StoryboardFileName" bundle:nil];
ViewEntryImageController *controller = (ViewEntryImageController *)[myStoryboard instantiateViewControllerWithIdentifier:@"ViewEntryImage"];

This assumes a storyboard name of StoryboardFileNameand that the view entry image controller has an identifier of ViewEntryImageset in the view properties (Attributes inspector, section "View Controller").

这假定情节提要名称为StoryboardFileName,并且视图条目图像控制器ViewEntryImage在视图属性(属性检查器,“视图控制器”部分)中设置了标识符。