IOS 切换视图和故事板不起作用
我在切换视图时遇到问题。 模拟器
我正在使用带有 xcode 4.2 Storyboard 的
- ,其中包含:
NavigationController
(初始视图控制器) UIViewController
与导航控制器有关系UIViewController
(与我的自定义类配对:ViewEntryImageController
)没有任何关系。包含一个按钮,一个底部工具栏,带有一些工具栏按钮。
用户进入UIViewController
,在这里他可以看到一个ScrollView
,并在ScrollView
中看到一些图像。
图像有一个手势:
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(openEntryImage)];
[image addGestureRecognizer:recognizer];
[recognizer release];
openEntryImage 函数:
(IBAction)openEntryImage
{
ViewEntryImageController *controller=[[ViewEntryImageController alloc]initWithNibName:nil bundle:nil];
controller.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
}
当我尝试点击图像时,openEntryImage
也可以工作(效果正确),但我看不到我的 ViewEntryImageController
> 查看和我的按钮,我只看到一个黑色的窗口。
我尝试将 NSLog 行放入 ViewEntryImageController
viewDidLoad
函数中,并且它有效,那么黑色窗口是什么以及我的视图控制器在哪里?
当我尝试使用pushViewController时,在新视图上我发现了一个带有后退按钮的导航工具栏,但没有其他控件。
我尝试了另一个版本,我创建了一个 UIViewController
类,但现在使用了一个 xib 文件。我用它代替了 ViewEntryImageController 并且它有效。为什么? 我也想在故事板中使用这个控制器。
I have a problem with switching views. I'm using a simulator with 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.
User come into the UIViewController
, where he can see a ScrollView
and in ScrollView
some images.
Images has a gesture:
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(openEntryImage)];
[image addGestureRecognizer:recognizer];
[recognizer release];
The openEntryImage function:
(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.
I try to put a NSLog line into the ViewEntryImageController
viewDidLoad
function, and it works, so what is the black window and where is my view controller?
When I try to use pushViewController
, on the new view I found a navigation toolbar with a back button, but no other controls.
I tried another version, I created a UIViewController
class, but now with a xib file. I used it instead of ViewEntryImageController
and it works. Why?
I want to use this controller in storyboard too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ViewEntryImageController
类本身没有有关如何构建对话框的信息。但是您可以从情节提要中自行实例化视图控制器:这假设情节提要名称为
StoryboardFileName
,并且视图条目图像控制器的标识符为ViewEntryImage
在视图属性(属性检查器,“视图控制器”部分)。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:This assumes a storyboard name of
StoryboardFileName
and that the view entry image controller has an identifier ofViewEntryImage
set in the view properties (Attributes inspector, section "View Controller").尝试这样:
如果您不使用 .nib 名称而是使用故事板,那就有点困难了。通过按住 ctrl 并从一个视图拖动到另一个视图,创建从控制器到 ViewEntryImageController 控制器的 Segue。单击此 segue 并为其指定一个标识符。
然后使用
[self PerformSegue:@"identifier"];
函数呈现下一个视图。Try it like this :
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.
Then use the
[self performSegue:@"identifier"];
function to present the next view.