Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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.
  • Loading branch information...
commit d87c92d5dc66c73160ef9e95647165d3a3f62fc9 1 parent 8faa4fd
@jverkoey jverkoey authored
View
6 src/Three20UINavigator/Headers/TTBaseNavigator.h
@@ -164,6 +164,12 @@
* with the top-most controller that contains this view that /isn't/ the container.
* If getNavigatorForController: returns a navigator, this navigator is returned.
* Otherwise, the global navigator is returned.
+ *
+ * If the given view is not, in fact, a view, which is the case if a UIBarButtonItem is passed,
+ * returns the global navigator via [TTBaseNavigator globalNavigator].
+ *
+ * If you need to use a specific navigator for UIBarButtonItem, handle the button tap
+ * yourself and use navigatorForView: on an actual view in the controller.
*/
+ (TTBaseNavigator*)navigatorForView:(UIView*)view;
View
6 src/Three20UINavigator/Sources/TTBaseNavigator.m
@@ -127,6 +127,12 @@ + (void)setGlobalNavigator:(TTBaseNavigator*)navigator {
///////////////////////////////////////////////////////////////////////////////////////////////////
+ (TTBaseNavigator*)navigatorForView:(UIView*)view {
+ // If this is called with a UIBarButtonItem, we can't traverse a view hierarchy to find the
+ // navigator, return the global navigator as a fallback.
+ if (![view isKindOfClass:[UIView class]]) {
+ return [TTBaseNavigator globalNavigator];
+ }
+
id<TTNavigatorRootContainer> container = nil;
UIViewController* controller = nil; // The iterator.
UIViewController* childController = nil; // The last iterated controller.
Please sign in to comment.
Something went wrong with that request. Please try again.