AAPLMasterViewController.m 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. File: AAPLMasterViewController.m
  3. Abstract: An iPad-only class that ensures that the root view controller of the application always has the bar button item displayed when in portrait. See AAPLSplitViewControllerDelegate for more information.
  4. Version: 2.12
  5. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
  6. Inc. ("Apple") in consideration of your agreement to the following
  7. terms, and your use, installation, modification or redistribution of
  8. this Apple software constitutes acceptance of these terms. If you do
  9. not agree with these terms, please do not use, install, modify or
  10. redistribute this Apple software.
  11. In consideration of your agreement to abide by the following terms, and
  12. subject to these terms, Apple grants you a personal, non-exclusive
  13. license, under Apple's copyrights in this original Apple software (the
  14. "Apple Software"), to use, reproduce, modify and redistribute the Apple
  15. Software, with or without modifications, in source and/or binary forms;
  16. provided that if you redistribute the Apple Software in its entirety and
  17. without modifications, you must retain this notice and the following
  18. text and disclaimers in all such redistributions of the Apple Software.
  19. Neither the name, trademarks, service marks or logos of Apple Inc. may
  20. be used to endorse or promote products derived from the Apple Software
  21. without specific prior written permission from Apple. Except as
  22. expressly stated in this notice, no other rights or licenses, express or
  23. implied, are granted by Apple herein, including but not limited to any
  24. patent rights that may be infringed by your derivative works or by other
  25. works in which the Apple Software may be incorporated.
  26. The Apple Software is provided by Apple on an "AS IS" basis. APPLE
  27. MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
  28. THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
  29. FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
  30. OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
  31. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
  32. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
  35. MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
  36. AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
  37. STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
  38. POSSIBILITY OF SUCH DAMAGE.
  39. Copyright (C) 2014 Apple Inc. All Rights Reserved.
  40. */
  41. #import "AAPLMasterViewController.h"
  42. #if DEBUG
  43. // FLEX should only be compiled and used in debug builds.
  44. #import "FLEXManager.h"
  45. #endif
  46. @implementation AAPLMasterViewController
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. #if DEBUG
  51. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"FLEX" style:UIBarButtonItemStylePlain target:self action:@selector(flexButtonTapped:)];
  52. #endif
  53. }
  54. - (void)flexButtonTapped:(id)sender
  55. {
  56. #if DEBUG
  57. [[FLEXManager sharedManager] showExplorer];
  58. #endif
  59. }
  60. // When a segue from the AAPLMasterViewController's table view is triggered, we want to ensure that the current detail view controller's
  61. // "More" bar button item is correctly transferred to the destination detail view controller's navigation item. We are only concerned about
  62. // this change when the application is in portrait mode since this is the only time that the "More" bar button item will be visible.
  63. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  64. #pragma clang diagnostic push
  65. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  66. if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
  67. #pragma clang diagnostic pop
  68. UINavigationController *newDetailViewController = [segue destinationViewController];
  69. UINavigationController *oldDetailViewController = [self.splitViewController.viewControllers lastObject];
  70. // In order for a segue to occur when the view controller is in portrait, the "More" bar button item must be visible.
  71. // However, the "More" bar button item is only visible if the detail view controller's root view controller is
  72. // visible (otherwise there would be a "Back" bar button item). We can then query the old detail view controller's top view
  73. // controller for the current "More" bar button item.
  74. UIBarButtonItem *currentDetailBarButtonItem = oldDetailViewController.topViewController.navigationItem.leftBarButtonItem;
  75. // The new detail view controller's root view controller will be the top view controller when it's initially
  76. // pushed onto the detail navigation controller.
  77. newDetailViewController.topViewController.navigationItem.leftBarButtonItem = currentDetailBarButtonItem;
  78. }
  79. }
  80. @end