A Modal View Controller example.
- version: 0.1.0
A Modal View Controller example. There is a presenting view controller and a presented view controller.
The best practice is for the presenting view controller to dismiss the presented view controller. This requires delegation. The Presented view controller defines a protocol method and a delegate property. The Presenting view controller adopts the PresentedViewControllerDelegate protocol.
You can also pass data back to the presenting view controller. To do this you could add an argument to this method.
####The Presenting View Controller
####The Presented View Controller
###Interesting Code Snippets
#####Presented View Controller declares the PresentedViewControllerDelegate protocol
@protocol PresentedViewControllerDelegate <NSObject>
- (void)dismissPresentedViewController;
@end#####Presenting View Controller adopts the PresentedViewControllerDelegate protocol
@interface PresentingViewController : UIViewController <PresentedViewControllerDelegate>
@end#####Presenting View Controller implements dismissPresentedViewController
- (void)dismissPresentedViewController
{
[self dismissViewControllerAnimated:YES completion:NULL];
}#####Presented View Controller has a weak reference to the delegate.
@property (nonatomic, weak) id <PresentedViewControllerDelegate> delegate;#####Presented View Controller uses the reference to the delegate.
- (IBAction)didSelectDone:(UIButton *)sender
{
[self.delegate dismissPresentedViewController];
}#####Prepare for Segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
PresentedViewController *viewController = segue.destinationViewController;
viewController.delegate = self;
}- Xcode 5
- Xcode 5
Download, unzip, open in Xcode
delete the directory
No Support.
Any contribution is highly appreciated. The best way to contribute code is to open a pull request on GitHub.
@iggym
OSL - Open Software Licence 3.0
(c) 2013 iggym

