Last active
August 29, 2015 14:02
-
-
Save michaelochs/a034f7dfddf1e6f3e1fa to your computer and use it in GitHub Desktop.
A template for a custom UIViewController with proper model handling. See http://www.ios-coding.com/blog/2014/06/22/model-handling-in-uiviewcontroller/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2014 bitecode, Michael Ochs | |
// | |
// See http://www.ios-coding.com/blog/2014/06/22/model-handling-in-uiviewcontroller/ | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
// MyViewController.h: | |
@interface MOCDefaultViewController : UIViewController | |
@property (nonatomic, strong, readwrite) MyModel *myModel; | |
@end | |
// MyViewController.m: | |
@implementation MOCDefaultViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self setupSubviewHierarchy]; | |
[self updateViewWithCurrentModel]; | |
} | |
- (void)setupSubviewHierarchy | |
{ | |
// if not using Interface Builder, setup your view hierarchy here | |
// do not use your model in here! | |
} | |
- (void)updateViewWithCurrentModel | |
{ | |
MyModel *myModel = self.myModel; | |
// set text labels, text inputs, switches and other UI components | |
// according to your model's state in here. | |
} | |
- (void)setMyModel:(MyModel *)myModel | |
{ | |
_myModel = myModel; | |
if (self.isViewLoaded) { | |
[self updateViewWithCurrentModel]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment