I have two views. One view is registration view. When user clicks on the registration UIBarButtonItem, it takes them to that view. On that view, there’s another UIBarbuttonitem that says “Back” – so when the user clicks on that button, it takes them to the main view that has registration button on it. Then if the user clicks on Sign up button again, it throws this error;
2012-09-26 19:22:53.256 Users[14763:c07] -[Registration signUp:]: unrecognized selector sent to instance 0x747e5b0
2012-09-26 19:22:53.257 Users[14763:c07] *** Terminating app due to uncaught exception
UsersViewController.h
@interface UsersViewController : UIViewController
@property (nonatomic, strong) Registration *registration;
UsersViewController.m
Signup event:
self.registration = [[Registration alloc]initWithNibName:@"Registration" bundle:nil];
[self.view addSubview:self.registration.view];
Registration.h
@interface Registration : UIViewController
@property (nonatomic, strong) Registration *mainView;
Registration.m
Back button Event
self.mainView = [[Registration alloc]initWithNibName:@"UsersViewController" bundle:nil];
[self.view addSubview:self.mainView.view]
When the bar button is pressed, the handling code should look like this:
Make sure your main view controller is embedded in a navigation controller and the OS should do the rest of the work for you. You’ll have a back button on your registration view controller that will take your user back to the previous view. addSubview is not the method generally used for navigating between views like this. You could also use
or if you’re using storyboards,
there’s a bunch of ways to do this but addSubview is not the droid you’re looking for.
Also, you don’t want to give your presented view controller a property that points to its presenter. You should read up on the delegation design pattern in Cocoa. You’ll want to give your Registration view controller a delegate property, assign the MainViewController as the Registration view controller’s delegate when it’s presented, and then implement a delegate call-back method for the MainViewController to do whatever work it needs to when your Registration view controller is dismissed.