自学ios开发之项目第一天~(微博项目)

来源:互联网 发布:阿里小号怎么登录淘宝 编辑:程序博客网 时间:2024/06/06 03:02

MJ的视频,看了一遍,总结了大部分内容

由于ios6已经淘汰,关于其中适配问题,都被我跳过去了,哈哈哈哈~

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

   application.statusBarHidden = NO;

//    1.创建窗口

    self.window =[[UIWindowalloc]init];

    self.window.frame = [UIScreenmainScreen].bounds;

//    设置根控制器

    HFTabBarController *tabbarVc = [[HFTabBarControlleralloc] init];

    self.window.rootViewController = tabbarVc;

    [self.windowmakeKeyAndVisible];

    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= [UIImageimageNamed: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 = [[UIViewControlleralloc] init];

    Vc.view.backgroundColor = [UIColoryellowColor];

    

    Vc.hidesBottomBarWhenPushed = YES;

    [self.navigationControllerpushViewController:Vc animated:YES];

//   NSLog(@"--%ld",indexPath.row);

}

容易写成didDeselect  引以为戒!!!

 

 

 

 


0 0