ios - Access UINavigationViewController from UIImageView class -
i have uiimageview custom class. when image pressed class should push new view controller, don't seem able reference current uinavigationcontroller. self.navigationcontroller, here can't. tried following code doesn't work:
[self.window.rootviewcontroller.navigationcontroller pushviewcontroller:browser animated:yes];
give custom image view delegate:
@protocol customimageviewdelegate; @interface customimageview : uiimageview @property (weak, nonatomic) id<customimageviewdelegate> delegate; @end @protocol customimageviewdelegate - (void)imageviewpressed:(customimageview *)imageview @end
make view controller delegate. when image pressed, [self.delegate imageviewpressed:self
.
your view controller have implementation:
- (void)imageviewpressed:(customimageview *)imageview { [self.navigationcontroller pushviewcontroller:browser animated:yes]; }
or give view navigation controller property:
@interface customimageview : uiimageview @property (weak, nonatomic) uinavigationcontroller navigationcontroller; @end
then can use [self.navigationcontroller pushviewcontroller:browser animated:yes]
directly on custom image view.
you'll have set navigationcontroller
property, ios won't you.
on controller add line
self.yourcustomimageviewproperty.navigationcontroller = self.navigationcontroller;
this basic response, hope steers in right direction.
Comments
Post a Comment