Skip to content

Commit 7af47c6

Browse files
committed
[UINavigator] Check the view class in navigatorForView.
When using openURLFromButton: we will likely be calling this from a UIBarButtonItem object, which isn't a descendant of the UIView class. We return the global navigator because there's no simple way to determine the class from the bar button item. This is a trade-off of ease-of-use over proper functionality here. If you want to get a UIBarButtonItem to open a specific navigator, handle the button tapped method yourself and get the correct navigator.
1 parent 41f43cb commit 7af47c6

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Three20UINavigator/Headers/TTBaseNavigator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@
164164
* with the top-most controller that contains this view that /isn't/ the container.
165165
* If getNavigatorForController: returns a navigator, this navigator is returned.
166166
* Otherwise, the global navigator is returned.
167+
*
168+
* If the given view is not, in fact, a view, which is the case if a UIBarButtonItem is passed,
169+
* returns the global navigator via [TTBaseNavigator globalNavigator].
170+
*
171+
* If you need to use a specific navigator for UIBarButtonItem, handle the button tap
172+
* yourself and use navigatorForView: on an actual view in the controller.
167173
*/
168174
+ (TTBaseNavigator*)navigatorForView:(UIView*)view;
169175

src/Three20UINavigator/Sources/TTBaseNavigator.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ + (void)setGlobalNavigator:(TTBaseNavigator*)navigator {
125125

126126
///////////////////////////////////////////////////////////////////////////////////////////////////
127127
+ (TTBaseNavigator*)navigatorForView:(UIView*)view {
128+
// If this is called with a UIBarButtonItem, we can't traverse a view hierarchy to find the
129+
// navigator, return the global navigator as a fallback.
130+
if (![view isKindOfClass:[UIView class]]) {
131+
return [TTBaseNavigator globalNavigator];
132+
}
133+
128134
id<TTNavigatorRootContainer> container = nil;
129135
UIViewController* controller = nil; // The iterator.
130136
UIViewController* childController = nil; // The last iterated controller.

0 commit comments

Comments
 (0)