Skip to content
This repository
Browse code

[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 7af47c6c93c6e19b99121618e479ad5461d64c61 1 parent 41f43cb
Jeff Verkoeyen authored December 12, 2010
6  src/Three20UINavigator/Headers/TTBaseNavigator.h
@@ -164,6 +164,12 @@
164 164
  * with the top-most controller that contains this view that /isn't/ the container.
165 165
  * If getNavigatorForController: returns a navigator, this navigator is returned.
166 166
  * 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.
167 173
  */
168 174
 + (TTBaseNavigator*)navigatorForView:(UIView*)view;
169 175
 
6  src/Three20UINavigator/Sources/TTBaseNavigator.m
@@ -125,6 +125,12 @@ + (void)setGlobalNavigator:(TTBaseNavigator*)navigator {
125 125
 
126 126
 ///////////////////////////////////////////////////////////////////////////////////////////////////
127 127
 + (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
+
128 134
   id<TTNavigatorRootContainer>  container = nil;
129 135
   UIViewController*             controller = nil;      // The iterator.
130 136
   UIViewController*             childController = nil; // The last iterated controller.

0 notes on commit 7af47c6

Please sign in to comment.
Something went wrong with that request. Please try again.