Skip to content

Commit d87c92d

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 8faa4fd commit d87c92d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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
@@ -127,6 +127,12 @@ + (void)setGlobalNavigator:(TTBaseNavigator*)navigator {
127127

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

0 commit comments

Comments
 (0)