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

发布于 2024-12-18 22:05:18 字数 1499 浏览 2 评论 0原文

我在切换视图时遇到问题。 模拟器

我正在使用带有 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 controller
  • UIViewController (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诠释孤独 2024-12-25 22:05:18

ViewEntryImageController 类本身没有有关如何构建对话框的信息。但是您可以从情节提要中自行实例化视图控制器:

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

这假设情节提要名称为 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:

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").

娇妻 2024-12-25 22:05:18

尝试这样:

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

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

然后使用[self PerformSegue:@"identifier"];函数呈现下一个视图。

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文