Iphone:在两个 UIViewController 之间来回移动时出现问题

发布于 2024-08-27 22:22:52 字数 1489 浏览 6 评论 0原文

我先描述一下问题的背景。我有 2 个 UIViewController 调用 AdminViewController 和 ButtonReorderViewController。 AdminViewController 包含 1 个按钮。 ButtonReorderViewController 包含 1 个按钮和 1 个图片。 AdminViewController 中的按钮与事件调用 goToReorderButton 相关联。 goToReorderButton 的内容如下:

ButtonReorderViewController *buttonReorder = [[ButtonReorderViewController alloc] initWithNibName:@"ButtonReorderViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:buttonReorder];  //Add a Navigation Controller to the root view
[navController setNavigationBarHidden:TRUE];
buttonReorder = (ButtonReorderViewController *) navController;
[[buttonReorder view] setFrame:CGRectMake(0, -20, 320, 470)];
[self.view addSubview:buttonReorder.view];

我使用 UINavigationController 来左右滑动。所以我在 AdminViewController 中,然后单击goToReorderButton,它加载ButtonReorderViewController。我可以左右滑动(太棒了!!!)所以我点击 ButtonReorderViewController 中的按钮调用 goToAdmin,只需返回到 AdminViewController

-(void) goToAdmin{
     [self.view removeFromSuperview];
}

但是,当我返回到 AdminViewController 时,我根本无法单击任何内容。该程序没有分段错误,只是我根本无法单击该按钮。如果我删除 goToReorderButton 内的 buttonReorder = (ButtonReorderViewController *) navController; 行,那么一切正常。知道如何解决这个问题吗?

Let me first describe the context of the problem. I have 2 UIViewController call AdminViewController and ButtonReorderViewController. AdminViewController contain 1 button. ButtonReorderViewController contains 1 button and 1 picture. Button in AdminViewController tie to an event call goToReorderButton. The content of goToReorderButton are below:

ButtonReorderViewController *buttonReorder = [[ButtonReorderViewController alloc] initWithNibName:@"ButtonReorderViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:buttonReorder];  //Add a Navigation Controller to the root view
[navController setNavigationBarHidden:TRUE];
buttonReorder = (ButtonReorderViewController *) navController;
[[buttonReorder view] setFrame:CGRectMake(0, -20, 320, 470)];
[self.view addSubview:buttonReorder.view];

I use UINavigationController to allow me to swipe left and right.So I am in AdminViewController, and I click on goToReorderButton, it load ButtonReorderViewController. I am able to swipe left and right (awesome !!!) So I click the button in ButtonReorderViewController call goToAdmin, simply to go back to the AdminViewController

-(void) goToAdmin{
     [self.view removeFromSuperview];
}

However, as soon as I go back to AdminViewController, I cant click anything at all. The program does not seg fault, it just that I cant click the button at all. if I remove the line buttonReorder = (ButtonReorderViewController *) navController; inside goToReorderButton, then everything work fine. Any idea how to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

咆哮 2024-09-03 22:22:53

我不确定我是否明白您的意思,但我认为您应该使用 UINavigationController 方法在视图控制器之间导航:

管理视图控制器应该是导航控制器的根视图控制器,然后您可以推送和弹出重新排序视图控制器。

在应用程序委托中(applicationDidFinishLaunching:方法):

// TODO: Instantiate the adminController

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:adminController];
[window addSubview:navController.view];

在AdminViewController中(事件处理程序方法内的按钮触摸):

// TODO: Instantiate the buttonReorder

[self.navigationController pushViewController:buttonReorder animated:YES];

在ButtonReorderViewController中(事件处理程序方法内的后退按钮触摸):

[self.navigationController popViewControllerAnimated:YES];

当然,您必须在使用视图控制器之前实例化它们......

干杯,
迈克尔.

I'm not sure that I follow you, but I think that you should use the UINavigationController methods to navigate between the view controllers:

The admin view controller should be the root view controller of the navigation controller and then you may push and pop the reorder view controller.

In app delegate (applicationDidFinishLaunching: method):

// TODO: Instantiate the adminController

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:adminController];
[window addSubview:navController.view];

In AdminViewController (button touch up inside event handler method):

// TODO: Instantiate the buttonReorder

[self.navigationController pushViewController:buttonReorder animated:YES];

In ButtonReorderViewController (back button touch up inside event handler method):

[self.navigationController popViewControllerAnimated:YES];

Of course, you have to instantiate the view controllers before using them...

Cheers,
Michael.

追我者格杀勿论 2024-09-03 22:22:53

听起来应用程序在您指出的那一行崩溃了。崩溃时调试控制台是否输出任何内容?

看起来 buttonReorder = (ButtonReorderViewController *) navController; 行在转换上失败。您确定 ButtonReorderViewController 扩展 UINavigationController 吗?如果没有,那么你就不能像这样投射它。

Sounds like the app crashed on that line you pointed out. Does the debug console output anything when it crashes?

Looks like the line buttonReorder = (ButtonReorderViewController *) navController; is failing on the cast. Are you sure ButtonReorderViewController extends UINavigationController? If not, then you can't cast it like that.

云醉月微眠 2024-09-03 22:22:53

我不确定,但我认为您可以使用 NavigationController 的 PusViewController 方法来完成您的工作。

I am not sure but i think you can use PusViewController method of NavigationController to do your job.

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