]> git.saurik.com Git - cydia.git/blob - CyteKit/TabBarController.mm
Hide custom function_ as an implementation detail.
[cydia.git] / CyteKit / TabBarController.mm
1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "CyteKit/UCPlatform.h"
23
24 #include "CyteKit/TabBarController.h"
25
26 #include "iPhonePrivate.h"
27
28 @implementation UITabBarController (Cydia)
29
30 @end
31
32 @implementation CyteTabBarController
33
34 - (void) didReceiveMemoryWarning {
35 [super didReceiveMemoryWarning];
36
37 // presenting a UINavigationController on 2.x does not update its transitionView
38 // it thereby will not allow its topViewController to be unloaded by memory pressure
39 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
40 UIViewController *selected([self selectedViewController]);
41 for (UINavigationController *controller in [self viewControllers])
42 if (controller != selected)
43 if (UIViewController *top = [controller topViewController])
44 [top unloadView];
45 }
46 }
47
48 - (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
49 if ([self unselectedViewController])
50 [self setUnselectedViewController:nil];
51
52 // presenting a UINavigationController on 2.x does not update its transitionView
53 // if this view was unloaded, the tranitionView may currently be presenting nothing
54 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
55 UINavigationController *navigation((UINavigationController *) viewController);
56 [navigation pushViewController:[[[UIViewController alloc] init] autorelease] animated:NO];
57 [navigation popViewControllerAnimated:NO];
58 }
59 }
60
61 - (void) dismissModalViewControllerAnimated:(BOOL)animated {
62 if ([self modalViewController] == nil && [self unselectedViewController] != nil)
63 [self setUnselectedViewController:nil];
64 else
65 [super dismissModalViewControllerAnimated:YES];
66 }
67
68 - (void) setUnselectedViewController:(UIViewController *)transient {
69 if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
70 if (transient != nil) {
71 [[[self viewControllers] objectAtIndex:0] pushViewController:transient animated:YES];
72 [self setSelectedIndex:0];
73 } return;
74 }
75
76 NSMutableArray *controllers = [[[self viewControllers] mutableCopy] autorelease];
77 if (transient != nil) {
78 UINavigationController *navigation([[[UINavigationController alloc] init] autorelease]);
79 [navigation setViewControllers:[NSArray arrayWithObject:transient]];
80 transient = navigation;
81
82 if (transient_ == nil)
83 remembered_ = [controllers objectAtIndex:0];
84 transient_ = transient;
85 [transient_ setTabBarItem:[remembered_ tabBarItem]];
86 [controllers replaceObjectAtIndex:0 withObject:transient_];
87 [self setSelectedIndex:0];
88 [self setViewControllers:controllers];
89 [self concealTabBarSelection];
90 } else if (remembered_ != nil) {
91 [remembered_ setTabBarItem:[transient_ tabBarItem]];
92 transient_ = transient;
93 [controllers replaceObjectAtIndex:0 withObject:remembered_];
94 remembered_ = nil;
95 [self setViewControllers:controllers];
96 [self revealTabBarSelection];
97 }
98 }
99
100 - (UIViewController *) unselectedViewController {
101 return transient_;
102 }
103
104 - (void) unloadData {
105 [super unloadData];
106
107 for (UINavigationController *controller in [self viewControllers])
108 [controller unloadData];
109
110 if (UIViewController *selected = [self selectedViewController])
111 [selected reloadData];
112
113 if (UIViewController *unselected = [self unselectedViewController]) {
114 [unselected unloadData];
115 [unselected reloadData];
116 }
117 }
118
119 #include "InterfaceOrientation.h"
120
121 @end