【问题标题】:IOS 8 SplitViewController iPhone simulator portrait detailView back button issueIOS 8 SplitViewController iPhone模拟器人像detailView后退按钮问题
【发布时间】:2014-12-09 18:13:44
【问题描述】:

这是斯坦福 iPhone 编程课程的作业。该程序的目的是浏览 tableViewControllers 中的照片并将它们显示在 ImageViewController 中。

原始代码是在 iOS 7 环境中编写的,因此它有两个用于 iPhone 和 iPad 的故事板。前者使用tabViewController,后者使用splitViewController。

由于 iOS 8 允许我们在 iPhone 和 iPad 中使用 splitViewController,所以我只是删除了 iPhone 故事板,并使用 iPad 的故事板作为通用布局。我的故事板布局是这样的: 哎呀,我不能在这里发布布局图像,没有足够的声誉。 click here to see the storyboard

我将连接两个 tableViewController 和最低 navigationViewController 的两个 segues 设置为“Show detail”。与 Xcode 模板“主从应用程序”相同,我将 splitViewController 设置为委托自身,并将我的 detailViewController(ImageViewController) 的 leftBarButtonItem 设置为 appDelegate 中的 displayModeButtonItem。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
    navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
    splitViewController.delegate = self;
    return YES;
}

问题在iPhone竖屏模式下,ImageViewController左上角没有“Master”后退按钮。在 iPad 模式下,一切正常。

我在这里链接我的代码:code for this program。希望有人能帮忙。谢谢!

【问题讨论】:

    标签: objective-c iphone ios8 uisplitviewcontroller back-button


    【解决方案1】:

    我在 ImageViewController 上使用了 unwind segue 技术(以编程方式)和自定义的左栏按钮(即细节视图)。

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
    
        // Need a back button to appear when not in split view i.e. iPhone mode
        // Wire up to unwind segue action
        if (!self.splitViewController) {
            UIImage *image = [UIImage imageNamed:@"ImageViewControllerBarBackIndicatorDefault"];
            UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
                                    initWithImage:image
                                    style:UIBarButtonItemStylePlain
                                    target:self
                                    action:@selector(OnClick_btnBack:)];
            self.navigationItem.leftBarButtonItem = btnBack;
        }
    }
    
    -(IBAction)OnClick_btnBack:(id)sender {
        [self performSegueWithIdentifier:@"unwind" sender:self];
    }
    
    #pragma Unwind Segue
    
    - (BOOL)canPerformUnwindSegueAction:(SEL)action
                 fromViewController:(UIViewController *)fromViewController
                         withSender:(id)sender {
        return YES;
    }
    
    - (IBAction)unwindFromImageViewController:(UIStoryboardSegue *)unwindSegue {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    

    【讨论】:

      【解决方案2】:

      我遇到了完全相同的问题。我从这里http://nshipster.com/uisplitviewcontroller/ 遵循了教程,但它仍然无法正常工作。不知道是什么问题..

      我最终以编程方式进行了切换。这不是最优雅的解决方案,但它正在发挥作用。

      if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
          self.navigationController?.pushViewController(settingsViewController, animated: true)
      } else {
          self.detailViewController?.setViewControllers([settingsViewController], animated: false)
      }
      

      【讨论】:

      • 我不懂 swift 语法。第一行是查看 userInterface 是否为 iPhone。什么问题
      • navigationController和.pushViewController之间的问号是什么意思?很抱歉没有完成最后评论的编辑。 (限时 5 分钟)
      • 使用问号可以检查引用是否为 nil,并且只有当引用不是 nil 时才会调用方法(pushViewController 或 setViewControllers)。基本上我将控制器推到 iphone 应用程序上,然后在 ipad 应用程序中更改当前的 detailViewController。希望这对你有帮助:)
      • 谢谢!所以你的 settingViewController 是 Master ViewController?
      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多