Last active
December 14, 2015 14:48
-
-
Save kharmabum/5103020 to your computer and use it in GitHub Desktop.
Template for UIViewController sublcass organization.
This file contains hidden or 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
| // | |
| // FTViewController.m | |
| // | |
| // Created by Juan-Carlos Foust on 06/03/2013. | |
| // | |
| #import "FTViewController.h" | |
| #import "MBProgressHUD.h" | |
| @interface FTViewController () | |
| @property (<#ref#>, nonatomic) <#type#> *<#variable#>; | |
| @end | |
| @implementation FTViewController | |
| #pragma mark - UITableViewDataSource and UITableViewDelegate | |
| -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| return [<#Cell Class#> heightForCell]; | |
| } | |
| - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView | |
| { | |
| NSInteger count = 1; | |
| return count; | |
| } | |
| - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | |
| { | |
| NSInteger count = 0; | |
| return count; | |
| } | |
| - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section | |
| { | |
| return @"Header Title"; | |
| } | |
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| static NSString *cellID = @"cellID"; | |
| UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; | |
| if (!cell) { | |
| cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; | |
| } | |
| NSString *text =[NSString stringWithFormat:@"Row %i", [indexPath row]]; | |
| [[cell textLabel] setText:text]; | |
| return cell; | |
| } | |
| - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| } | |
| #pragma mark - Actions, Gestures, Notification Handlers | |
| - (void)exit | |
| { | |
| [self dismissViewControllerAnimated:YES completion:NULL]; | |
| } | |
| #pragma mark - Private | |
| - (void)failWithMessage:(NSString *)status | |
| { | |
| [MBProgressHUD hideHUDForView:self.view animated:YES]; | |
| MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:NO]; | |
| [hud setLabelText:status]; | |
| [self performBlockOnMainThread:^{ | |
| [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; | |
| [self performBlockOnMainThread:^{hud.labelText = @"";} afterDelay:0.33f]; | |
| } afterDelay:1.5f]; | |
| } | |
| #pragma mark - UIViewController | |
| - (void)dealloc | |
| { | |
| [self removeObserver:<#(NSObject *)#> forKeyPath:<#(NSString *)#> context:<#(void *)#>]; | |
| } | |
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| [account addObserver:<#observer#> | |
| forKeyPath:<#key.path#> | |
| options:(NSKeyValueObservingOptionNew | | |
| NSKeyValueObservingOptionOld) | |
| context:NULL]; | |
| } | |
| - (void)viewDidUnload { | |
| [super viewDidUnload]; | |
| } | |
| - (void)viewWillAppear:(BOOL)animated { | |
| [super viewWillAppear:animated]; | |
| } | |
| - (void)viewDidAppear:(BOOL)animated { | |
| [super viewDidAppear:animated]; | |
| } | |
| - (void)viewWillDisappear:(BOOL)animated { | |
| [super viewWillDisappear:animated]; | |
| } | |
| - (void)viewDidDisappear:(BOOL)animated { | |
| [super viewDidDisappear:animated]; | |
| } | |
| #pragma mark - Segue | |
| - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)activityView | |
| { | |
| if ([segue.identifier isEqualToString:<#name#>]) { | |
| <#Class Name#> *vc = (<#Class Name#> *)segue.destinationViewController; | |
| <#initialization#> | |
| } | |
| } | |
| #pragma mark - KVO | |
| - (void)observeValueForKeyPath:(NSString *)keyPath | |
| ofObject:(id)object | |
| change:(NSDictionary *)change | |
| context:(void *)context { | |
| if ([keyPath isEqual:<#key path#>]) { | |
| [<#do something with#> | |
| [change objectForKey:NSKeyValueChangeNewKey]]; | |
| } | |
| /* | |
| Call the superclass's implementation *if it implements it*. | |
| NSObject does not implement the method. | |
| [super observeValueForKeyPath:keyPath | |
| ofObject:object | |
| change:change | |
| context:context]; | |
| */ | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment