Iphone:在两个 UIViewController 之间来回移动时出现问题
我先描述一下问题的背景。我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定我是否明白您的意思,但我认为您应该使用 UINavigationController 方法在视图控制器之间导航:
管理视图控制器应该是导航控制器的根视图控制器,然后您可以推送和弹出重新排序视图控制器。
在应用程序委托中(applicationDidFinishLaunching:方法):
在AdminViewController中(事件处理程序方法内的按钮触摸):
在ButtonReorderViewController中(事件处理程序方法内的后退按钮触摸):
当然,您必须在使用视图控制器之前实例化它们......
干杯,
迈克尔.
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):
In AdminViewController (button touch up inside event handler method):
In ButtonReorderViewController (back button touch up inside event handler method):
Of course, you have to instantiate the view controllers before using them...
Cheers,
Michael.
听起来应用程序在您指出的那一行崩溃了。崩溃时调试控制台是否输出任何内容?
看起来
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 sureButtonReorderViewController
extendsUINavigationController
? If not, then you can't cast it like that.我不确定,但我认为您可以使用 NavigationController 的 PusViewController 方法来完成您的工作。
I am not sure but i think you can use PusViewController method of NavigationController to do your job.