1.在Supporting Files建立幾個(gè)文件, 兩個(gè).h文件 (Enums.h 和 Marcros.h)以及一個(gè).pch文件;
Marcos.h 中 都是 一些宏定義静秆,包括第三方平臺的APPKey以及服務(wù)器ip;
Enums.h中 是一些自定義的類目粮揉,其中第一個(gè)類目就是標(biāo)識UIViewController的,
2. 這里主要說一下抚笔,代碼扶认,sb,xib, 結(jié)合寫項(xiàng)目殊橙,在一個(gè)PageController: NSObject ?.h文件中
@class UIViewController;
@interface PageController : NSObject
- (UIViewController *)defaultController;
- (void)gotoNext:(PageName)page animated:(BOOL)animated withObject:(NSObject *)object;
- (void)backToPrevious:(BOOL)animated withObject:(NSObject *)object;
- (void)gotoNext:(PageName)page;
- (void)gotoNext:(PageName)page withObject:(NSObject *)object;
- (void)backToPrevious;
- (void)backToPreviousWithObject:(NSObject *)object;
- (void)backToPage:(PageName)page;
- (void)pop:(PageName)page;
- (void)closePop;
- (void)clearAllPage;
- (void)updatePageEvent:(PageEvent)event;
- (PageEvent)consumePageEvent;
@end
.m 文件
- (void)gotoNext:(PageName)page animated:(BOOL)animated withObject:(NSObject *)object {
PageBase* pageBase = [self getPage:page];
if (pageBase != nil && [self currentNavigation] != nil) {
pageBase.back = NO;
pageBase.previousPage = self.currentPage;
pageBase.bundle = object;
self.currentPage = page;
if (page == MAIN_PAGE) {
[[self currentNavigation] setViewControllers:@[]];
}
[[self currentNavigation] pushViewController:pageBase animated:animated];
}
}
- (void)backToPrevious:(BOOL)animated withObject:(NSObject *)object {
if ([self currentNavigation] != nil) {
if ([[self currentNavigation] popViewControllerAnimated:animated]) {
PageBase* pageBase = (PageBase *)[[self currentNavigation] topViewController];
if (pageBase != nil) {
pageBase.back = YES;
pageBase.previousPage = self.currentPage;
pageBase.bundle = object;
self.currentPage = pageBase.currentPage;
}
}
else {
[self closePop];
}
}
}
#pragma mark - Private Methods -
- (PageBase *)getPage:(PageName)page {
NSArray* pageObj = [[self pages] objectForKey:[NSNumber numberWithInteger:page]];
if (pageObj != nil) {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:[pageObj objectAtIndex:0] bundle:nil];
if (storyboard != nil) {
PageBase *pageBase = [storyboard instantiateViewControllerWithIdentifier:[pageObj objectAtIndex:1]];
pageBase.currentPage = page;
pageBase.pageName = [pageObj objectAtIndex:1];
return pageBase;
}
}
return nil;
}
- (UINavigationController *)pushNavigationWithPage:(PageBase *)page {
UINavigationController* navigation = [[UINavigationController alloc] init];
navigation.navigationBarHidden = YES;
if (page) {
[m_navigations addObject:@{@"base": page, @"navigation": navigation}];
}
else {
[m_navigations addObject:@{@"base": [NSNull null], @"navigation": navigation}];
}
return navigation;
}
- (NSDictionary *)pages {
if (!m_pages) {
m_pages = @{
INT(LAUNCH_PAGE):? ? ? ? ? ? ? ? ? @[@"Launch",? ? @"LaunchPage"],
INT(TUTORIAL_PAGE):? ? ? ? ? ? ? ? @[@"Launch",? ? @"TutorialPage"],
};
}
return m_pages;
}