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
IOS Switch view and storyboard not works
提问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)UIViewController
which has relationship with the navigation controllerUIViewController
(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 ScrollView
and in ScrollView
some images.
用户进入UIViewController
,在那里他可以看到一些图像中的ScrollView
和ScrollView
。
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 openEntryImage
works as well (the effect is correct), but I don't see my ViewEntryImageController
view and my buttons, I'm only see a black window.
当我尝试点击图像时,openEntryImage
效果也很好(效果是正确的),但是我看不到我的ViewEntryImageController
视图和按钮,我只能看到一个黑色窗口。
I try to put a NSLogline into the ViewEntryImageController
viewDidLoad
function, and it works, so what is the black window and where is my view controller?
我尝试将NSLog行放入该ViewEntryImageController
viewDidLoad
函数中,并且可以正常工作,那么黑色窗口是什么,我的视图控制器在哪里?
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 UIViewController
class, but now with a xibfile. I used it instead of ViewEntryImageController
and 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 ViewEntryImageController
class 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 StoryboardFileName
and that the view entry image controller has an identifier of ViewEntryImage
set in the view properties (Attributes inspector, section "View Controller").
这假定情节提要名称为StoryboardFileName
,并且视图条目图像控制器ViewEntryImage
在视图属性(属性检查器,“视图控制器”部分)中设置了标识符。