【问题标题】:Question about UISegmentedControl and UINavigationController关于 UISegmentedControl 和 UINavigationController 的问题
【发布时间】:2011-08-09 07:46:29
【问题描述】:

我遇到了问题。我尝试使用基于导航的应用程序创建一个项目。
当我按下 rightBarButtonItem 时,推送到下一个视图。
该视图在 UINavigationBar 上获得了 UISegmentedControl。

按下按钮 A 时我使用 IBAction:

-(IBAction)backButtonPressed:(id)sender{
[self.navigationController popViewControllerAnimated:YES];}

当第一个视图出现时,我按下按钮 A 它将返回主视图。
如果我在 UISegmentedControl 上按数字 2,它会变成另一个视图,
仍然是相同的方法(-(IBAction)backButtonPressed:(id)sender)。
但是当我按下 Button 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];
}

}

有什么问题吗??
预先感谢。

迷你

【问题讨论】:

    标签: iphone xcode uinavigationcontroller uisegmentedcontrol


    【解决方案1】:

    我假设 seg_view 的 viewController 已被推送到 navigationController 的堆栈中,seg_view-Controller 上的 self.navigationController 然后返回您的 navigationController。但是,当从其他 viewControllers AView/BView 向其添加子视图时,这些 UIViewControllers 与 seg_view 的 Controller 或 navigationController 本身没有连接。这意味着新的 AView/BView 中的 self.navigationController 为零!根据您的实现,没有调用 backButtonPressed 或 AView 或 BView 中的 popViewController 什么都不做,因为它们没有导航控制器。我建议您要么不要使用其他 viewController(将 2 个视图与 seg_view 放在同一个 nib 中并互换它们),要么将它们推送到 navigationController 的堆栈中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多