I wants to open a UIViewController on Click of UIButton which is inside a UIView . The UIView has it's own .h & .m file & The action property of button is declared inside the it.
the navigation code is working fine if I am calling it from UIViewController of UIbutton which is like
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FilterDemoTableViewController *viewController = (FilterDemoTableViewController*) [mainStoryboard instantiateViewControllerWithIdentifier: @"FilterDemoTableViewController_Id"];
[[self navigationController]pushViewController:viewController animated:YES];
but if same code is calling from UIView .m file then it's not working plz help me.
And it won't. You can't call [self navigationController]
inside UIView
because it doesn't have one.
All you have to do is to reference the ViewController that owns your UIView
and call a method there.
Typically, you can do it with NSNotification
- not the best way but definitely works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.