Created
December 17, 2011 16:41
-
-
Save andreyvit/1490672 to your computer and use it in GitHub Desktop.
A demo of UIViewController-like class (PageViewController)
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
#import <UIKit/UIKit.h> | |
@class PageInfo; | |
@protocol PageViewControllerDelegate; | |
@interface PageViewController : NSObject { | |
NSInteger pageIndex; | |
id<PageViewControllerDelegate> delegate; | |
PageInfo *pageData; | |
NSString *_nibName; | |
// for "sliding message" | |
UIView *_messageView; | |
UILabel *_sectionEndStarLabel; | |
UILabel *_sectionEndMessageLabel; | |
UILabel *_titleLabel; | |
UILabel *_messageLabel; | |
} | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil; | |
@property(nonatomic) NSInteger pageIndex; | |
@property(nonatomic, assign) id<PageViewControllerDelegate> delegate; | |
@property(nonatomic, retain) PageInfo *pageData; | |
@property(nonatomic, retain) IBOutlet UIView *view; | |
- (void)loadView; | |
- (void)viewDidLoad; | |
- (void)viewDidUnload; | |
- (void)didReceiveMemoryWarning; | |
- (void)viewWillAppear:(BOOL)animated; | |
- (void)viewWillDisappear:(BOOL)animated; | |
- (void)viewDidAppear:(BOOL)animated; | |
- (void)viewDidDisappear:(BOOL)animated; | |
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated; | |
- (void)dismissModalViewControllerAnimated:(BOOL)animated; | |
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; | |
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; | |
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; | |
- (void)addSlidingMessageWithTitle:(NSString *)title message:(NSString *)message sectionEnd:(BOOL)sectionEnd; | |
- (void)layoutSlidingMessageWithContentY:(CGFloat)contentY contentHeight:(CGFloat)contentHeight scaleFactor:(BOOL)scaleFactor; | |
@end | |
@protocol PageViewControllerDelegate <NSObject> | |
- (void)changePage:(int)page iAm:(int)t; | |
- (void)tocHide; | |
- (void)tocUnHide; | |
@end |
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
#import "PageViewController.h" | |
@implementation PageViewController | |
@synthesize pageIndex; | |
@synthesize delegate; | |
@synthesize pageData; | |
@synthesize view=_view; | |
#pragma mark - | |
#pragma mark UIViewController emulation | |
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | |
if (self = [super init]) { | |
_nibName = [nibNameOrNil copy]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; | |
} | |
return self; | |
} | |
- (UIView *)view { | |
if (_view == nil) { | |
[self loadView]; | |
NSAssert(_view != nil, @"self.view not loaded by loadView"); | |
[self viewDidLoad]; | |
} | |
return _view; | |
} | |
- (void)setView:(UIView *)view { | |
if (view != _view) { | |
[_view release]; | |
_view = [view retain]; | |
} | |
} | |
- (void)loadView { | |
if ([_nibName length] == 0) { | |
_nibName = [NSStringFromClass([self class]) retain]; | |
} | |
[[NSBundle mainBundle] loadNibNamed:_nibName owner:self options:nil]; | |
NSAssert1(_view != nil, @"self.view outlet is not connected in %@", _nibName); | |
} | |
- (void)viewDidLoad { | |
// to be overridden | |
} | |
- (void)viewDidUnload { | |
// to be overridden | |
[_sectionEndStarLabel release], _sectionEndStarLabel = nil; | |
[_sectionEndMessageLabel release], _sectionEndMessageLabel = nil; | |
[_titleLabel release], _titleLabel = nil; | |
[_messageLabel release], _messageLabel = nil; | |
} | |
- (void)didReceiveMemoryWarning { | |
if (_view != nil && _view.superview == nil) { | |
[_view release], _view = nil; | |
[self viewDidUnload]; | |
} | |
} | |
- (void)dealloc { | |
[pageData release], pageData = nil; | |
delegate = nil; | |
[_sectionEndStarLabel release], _sectionEndStarLabel = nil; | |
[_sectionEndMessageLabel release], _sectionEndMessageLabel = nil; | |
[_titleLabel release], _titleLabel = nil; | |
[_messageLabel release], _messageLabel = nil; | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; | |
[_nibName release], _nibName = nil; | |
[_view release], _view = nil; | |
[super dealloc]; | |
} | |
- (void)viewWillAppear:(BOOL)animated { | |
} | |
- (void)viewWillDisappear:(BOOL)animated { | |
} | |
- (void)viewDidAppear:(BOOL)animated { | |
} | |
- (void)viewDidDisappear:(BOOL)animated { | |
} | |
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated { | |
} | |
- (void)dismissModalViewControllerAnimated:(BOOL)animated { | |
} | |
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { | |
} | |
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { | |
} | |
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment