关于 UISegmentedControl 和 UINavigationController 的问题
我遇到问题了。我尝试使用基于导航的应用程序创建一个项目。
当我按 rightBarButtonItem 时,推送到下一个视图。
该视图在 UINavigationBar 上有一个 UISegmentedControl。
我在按下按钮 A 时使用 IBAction:
-(IBAction)backButtonPressed:(id)sender{
[self.navigationController popViewControllerAnimated:YES];}
当第一个视图显示时,我按下按钮 A 它将消失返回主视图。
如果我在 UISegmentedControl 上按数字 2,它就会变成另一个视图,
仍然是相同的方法(-(IBAction)backButtonPressed:(id)sender)。
但是当我按下按钮 B 时,它不会返回主视图..
以下是我关于 UISegmentedControl 的方法:
-(void)showSegmentedView:(id)sender{
AView *aView = [[AView alloc] initWithNibName:@"AView" bundle:nil];
BView *bView = [[BView alloc] initWithNibName:@"BView" bundle:nil];
if(seg.selectedSegmentIndex ==0) {
[[seg_view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[seg_view addSubview:aView.view];
}
else if(seg.selectedSegmentIndex ==1){
[[seg_view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[seg_view addSubview:bView.view];
}
}
有什么问题吗??
提前致谢。
小型的
I got a problem. I try to create a project with Navigation-based Application.
When I press rightBarButtonItem push to next view.
And that view got a UISegmentedControl right on UINavigationBar.
I use a IBAction when press Button A:
-(IBAction)backButtonPressed:(id)sender{
[self.navigationController popViewControllerAnimated:YES];}
when first view show up, I press Button A it will go back to main view.
If I press number 2 on UISegmentedControl , it become to another View,
and still the same method(-(IBAction)backButtonPressed:(id)sender).
But when I press Button B , it wont go back to main view..
as follow is my method about UISegmentedControl:
-(void)showSegmentedView:(id)sender{
AView *aView = [[AView alloc] initWithNibName:@"AView" bundle:nil];
BView *bView = [[BView alloc] initWithNibName:@"BView" bundle:nil];
if(seg.selectedSegmentIndex ==0) {
[[seg_view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[seg_view addSubview:aView.view];
}
else if(seg.selectedSegmentIndex ==1){
[[seg_view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
[seg_view addSubview:bView.view];
}
}
Does anything wrong??
Thank in advance.
Mini
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设seg_view的viewController已被推送到navigationController的堆栈上,seg_view-Controller上的self.navigationController然后返回您的navigationController。但是,当从其他 viewController AView/BView 添加子视图时,这些 UIViewController 与 seg_view 的 Controller 或 navigationController 本身没有连接。这意味着新 AView/BView 中的 self.navigationController 为零!根据您的实现,backButtonPressed 不会被调用,或者 AView 或 BView 中的 popViewController 不执行任何操作,因为它们没有 navigationController。我建议您要么不要使用其他 viewController(将 2 个视图放在与 seg_view 相同的笔尖中并交换它们),要么将它们推送到 navigationController 的堆栈上。
I assume seg_view's viewController has been pushed onto the navigationController's stack, self.navigationController on seg_view-Controller then returns your navigationController. However, as when add subviews to it from other viewControllers AView/BView, those UIViewControllers have no connection to seg_view's Controller or the navigationController itself. That means self.navigationController inside the new AView/BView is nil! Depending on your implementation, either backButtonPressed doesn't get called or popViewController in AView or BView does nothing since they don't have a navigationController. I suggest your either don't use other viewControllers (put the 2 views in the same nib as seg_view and interchange them) or push them on the navigationController's stack.