关于 UISegmentedControl 和 UINavigationController 的问题

发布于 2024-11-02 14:03:37 字数 1191 浏览 1 评论 0原文

我遇到问题了。我尝试使用基于导航的应用程序创建一个项目。
当我按 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.
enter image description here

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..
enter image description here

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 技术交流群。

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

发布评论

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

评论(1

亢潮 2024-11-09 14:03:37

我假设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.

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