The normal way to open another screen from within a FirstVC screen, so one can close it again is like this:
SecondVC *secondVC = [[SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil];
secondVC.delegate = self; //needed to dismiss
[self presentModalViewController: secondVC animated: YES];
while the SecondVC.m has to import a protocol that declares the method called to close the SecondVC
So I always have to create a protocol file SecondVCProtocol.h which basically looks like this:
@protocol SecondVCProtocol <NSObject>
-(void)secondVCDidFinish;
@end
Then in SecondVC.m I need to import this SecondVCProtocol.h file and now can finally call
[self.delegate secondVCDidFinish]
I have just completed another Android app and beeing back in the iOS world, I find this rather cumbersome. – needing to define such a protocol in a separate file & needing to use a delegate – all just to do the most normal task like closing a screen…
Isn’t there an easier less complex way or is this just the way it has to be done?
for example like [self dismiss] in SecondVC – no delegate, no protocol – wouldn’t his be really nice?
Many thanks!
You can just call
on the presented viewcontroller, although it is not exactly best practice.
From Apple’s documentation:
Also from Apple’s documentation though (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html)