MJ的视频,看了一遍,总结了大部分内容
由于ios6已经淘汰,关于其中适配问题,都被我跳过去了,哈哈哈哈~
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
application.statusBarHidden = NO;
// 1.创建窗口
self.window =[[UIWindow alloc]init];
self.window.frame = [UIScreen mainScreen].bounds;
// 设置根控制器
HFTabBarController *tabbarVc = [[HFTabBarController alloc] init];
self.window.rootViewController = tabbarVc;
[self.window makeKeyAndVisible];
return YES;
}
1.在AppDelegate里先创建window 设置根控制器 然后生成并显示
2.采用分类之后mvc模式进行创建文件架构,直接在项目中创建文件夹是虚文件夹,可以在实际位置创建然后拖拽源文件到文件夹,然后在项目中删除已经报错的文件。
3.设置tabbar的vc 自定义tableviewVC 创建子控制器 然后添加到tabbar的控制器中
注意点:代码的抽取和封装
抽取:
/**
* 添加一个子控制器
*
* @param chileVc 子控制器名称
* @param title 标题
* @param imageName 图片名称
* @param selectImageName 选中图片名称
*/
- (void)addOneChileVc:(UIViewController*)chileVc title:(NSString *)titleimageName:(NSString *)imageNameselectImageName:(NSString *)selectImageName
{
// UIViewController *me = [[UIViewController alloc] init];
chileVc.view.backgroundColor = HFRandomColor; 这行代码会导致提前加载view,应该删掉
chileVc.tabBarItem.image= [UIImage imageNamed:imageName];
chileVc.title = title; //等于下面两行代码
// chileVc.navigationItem.title = title;
// chileVc.tabBarItem.title = title;
UIImage *selectedImage = [UIImageimageNamed:selectImageName];
// 设置渲染模式使图标不被系统进行第二次渲染,导致选中图片修改失败
selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
chileVc.tabBarItem.selectedImage = selectedImage;
// 包装导航控制器使tabbar的根控制器为导航控制器
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:chileVc];
[self addChildViewController:nav];
}
很重要的思想,在做适配图的时候 类似的图片名称可以这么处理 采用category
if (IOS7) {
NSString *newName = [imageName stringByAppendingString:@"_os7"];
image = [UIImage imageNamed:newName];
}
if (image == nil){
image = [UIImage imageNamed:imageName];
}
return image;
非常重要的容易出错的地方:
在使用这个方法的时候
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
UIViewController *Vc = [[UIViewController alloc] init];
Vc.view.backgroundColor = [UIColor yellowColor];
Vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:Vc animated:YES];
// NSLog(@"--%ld",indexPath.row);
}
容易写成didDeselect 引以为戒!!!