1.在Supporting Files建立几个文件, 两个.h文件 (Enums.h 和 Marcros.h)以及一个.pch文件;
Marcos.h 中 都是 一些宏定义,包括第三方平台的APPKey以及服务器ip;
Enums.h中 是一些自定义的类目,其中第一个类目就是标识UIViewController的,
2. 这里主要说一下,代码,sb,xib, 结合写项目,在一个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;
}
网友评论