标签:
1.准备第三方
2. tabbar标签页
//程序的window分配内存 self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; [self.window makeKeyAndVisible]; self.window.backgroundColor = [UIColor orangeColor]; self.window.rootViewController = [MyTabBarController new]; // self.window.rootViewController = [DetailViewController new]; return YES;
//读取plist文件 NSString *path = [[NSBundle mainBundle]pathForResource:@"Limit" ofType:@"plist"]; NSArray *fileArr = [NSArray arrayWithContentsOfFile:path]; //创建五个页面,并且设置,页面tabbarItem,使用系统的tabBar for (NSDictionary *dic in fileArr) { NSString *name = dic[@"name"]; NSString *icon = dic[@"icon"]; NSString *title = dic[@"title"]; //创建nav和vc, //注意UINavigationController的navigationItem,在它的跟视图 //注意MyTabBarController的tabBarItem,在它的跟视图 UIViewController *vc = [NSClassFromString(name) new]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; [self addChildViewController:nav]; //设置navagationItem内容 vc.navigationItem.title = title; //设置tabBarItem内容 nav.tabBarItem.title = title; nav.tabBarItem.image = [UIImage imageNamed:icon]; } //以前我创建页面,通过一个个来,现在用for循环,可是怎么循环,通过其实我们只需要类名来创建,,,用plist,神器 self.tabBar.translucent = NO;
3.接口
// // Header.h // FreeDemo // // #ifndef FreeDemo_Header_h #define FreeDemo_Header_h //限免 #define k_LIMIT_URL @"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=%d" //降价 #define k_SALES_URL @"http://iappfree.candou.com:8080/free/applications/sales?currency=rmb&page=%d" //免费 #define k_FREE_URL @"http://iappfree.candou.com:8080/free/applications/free?currency=rmb&page=%d" //专题 #define k_SPECIAL_URL @"http://iappfree.candou.com:8080/free/special?page=%d&limit=5" #define n_SPECIAL_URL @"http://10.0.8.10/app/qfts/iappfree/api/topic.php?page=%d&number=5" //热榜 #define k_HOSTLIST_URL @"http://open.candou.com/mobile/hot/page/%d" #define n_HOSTLIST_URL @"http://10.0.8.10/app/qfts/iappfree/api/hot.php?page=%d&number=10" //详情 #define k_DETAIL_URL @"http://iappfree.candou.com:8080/free/applications/%@?currency=rmb" //附近的人在用 #define k_RECOMMEND_URL @"http://iappfree.candou.com:8080/free/applications/recommend?longitude=116.344539&latitude=40.034346" //分类 #define k_SORTLIST_LIMITED_URL @"http://iappfree.candou.com:8080/free/categories/limited" #define k_SORTLIST_SALES_URL @"http://iappfree.candou.com:8080/free/categories/sales" #define k_SORTLIST_FREE_URL @"http://iappfree.candou.com:8080/free/categories/free" #define n_SORTLIST_URL @"http://10.0.8.10/app/qfts/iappfree/api/appcate.php" //分类的内容 //限免分类 #define k_LIST_LIMITED_URL @"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=%d&category_id=" //降价分类 #define k_LIST_SALES_URL @"http://iappfree.candou.com:8080/free/applications/sales?currency=rmb&page=%d&category_id=" //免费分类 #define k_LIST_FREE_URL @"http://iappfree.candou.com:8080/free/applications/free?currency=rmb&page=%d&category_id=" //热榜分类 #define k_LIST_HOST_URL @"http://open.candou.com/mobile/hot/page/%d&category_id=" #define n_LIST_HOST_URL @"http://10.0.8.10/app/qfts/iappfree/api/hot.php?page=%d&number=10&cate_id=" #define k_CANDOU_URL @"http://open.candou.com/mobile/candou" //屏幕高度 #define k_screen_height [UIScreen mainScreen].bounds.size.height #define k_defautIcon (@"appproduct_appdefault") #endif
4.基础页面(一个页面--等于--一个控制器), 设置所有页面
#import "MJLConetctionManager.h" #import "Header.h" #import "UIImageView+WebCache.h" typedef NS_ENUM(NSInteger, item_position) { item_left = 0, item_right }; /** * 设置导航条按钮 * * @param position 位置 * @param title 文字 * @param image 背景图 * @param action 执行方法 */ -(void)customNavigationItem:(int)position title:(NSString *)title image:(UIImage *)image action:(SEL)action; /** * 缓存到本地 * * @param data 需要缓存的二进制数据 */ -(void)wirieToLocal:(NSData *)data; /** * 读取缓存 * * @return 读取的二进制数据 */ -(NSData *)readLocal;
//抽取的共性页面,非实际页面 //设置背景色,自动偏移 self.view.backgroundColor = [UIColor whiteColor]; self.automaticallyAdjustsScrollViewInsets = NO; /** * 实现 * * @param position <#position description#> * @param title <#title description#> * @param image <#image description#> * @param action <#action description#> */ -(void)customNavigationItem:(int)position title:(NSString *)title image:(UIImage *)image action:(SEL)action{ //设置按钮 UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(0, 0, 60, 30); [btn setBackgroundImage:image forState:UIControlStateNormal]; [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; [btn setTitle:title forState:UIControlStateNormal]; UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:btn]; if (position == item_left) { self.navigationItem.leftBarButtonItem = item; }else{ self.navigationItem.rightBarButtonItem = item; } } /** * 实现 * * @param data <#data description#> */ -(void)wirieToLocal:(NSData *)data{ NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@.txt",NSStringFromClass([self class])]; [data writeToFile:path atomically:YES]; } /** * 实现 * * @return <#return value description#> */ -(NSData *)readLocal{ NSString *path = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/%@.txt",NSStringFromClass([self class])]; if ([[NSFileManager defaultManager]fileExistsAtPath:path]) { return [NSData dataWithContentsOfFile:path]; }else{ return nil; } } /** * 页面和网络请求共存亡 */ -(void)dealloc{ //当页面销毁,需要停止所有的网络请求 [[MJLConetctionManager defaultManeger]stopConnectionForTarge:self]; }
标签:
原文地址:http://www.cnblogs.com/coderMJL/p/4858908.html