代碼搭建記事本架構(一)

來源:互聯網
上載者:User

標籤:

糾結數天,終於下定決心開始搭建屬於自己的記事本。

寫在最前面:這兩天是有些彷徨,加上重感冒,難受的要死。思路有些混亂,介面想了一下大概,就胡亂的開始了。但是總算是邁出了第一步。

將rootviewcontroller設定為tabbar

   application.statusBarHidden = YES;        self.window = [[UIWindow alloc]init];    self.window.frame = [[UIScreen mainScreen]bounds];        self.window.rootViewController = [[CSMainBarController alloc]init];        [self.window makeKeyAndVisible  ];

 

 

採用的tabbarcontroller 上面套上uinavcontroller  在加上tableviewcontroller 代碼如下:

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.//    CSMineTableViewController *mineTabelview = [[CSMineTableViewController alloc]init];    CSMineTableViewController *mineTable =[[CSMineTableViewController alloc ]init];    [self setTabbarController:mineTable Title:@"關於我" image:@"tabbar_profile_os7" selectImage:@"tabbar_profile_selected"];    CSDiaryTableViewController *diaryTable = [[CSDiaryTableViewController alloc]init];    [self setTabbarController:diaryTable Title:@"哈哈" image:@"tabbar_profile_os7" selectImage:@"tabbar_profile_selected"];        CSSettingViewController *setView = [[CSSettingViewController alloc]init];    [self setTabbarController:setView Title:@"餓了" image:@"tabbar_profile_os7" selectImage:@"tabbar_profile_selected"];        CSDuanZiViewController *duanzi  = [[CSDuanZiViewController alloc]init];    [self setTabbarController:duanzi Title:@"餓了" image:@"tabbar_profile_os7" selectImage:@"tabbar_profile_selected"];}/** *   設定對應的tabbar的屬性 * *  @param childVC     <#childVC description#> *  @param tile        <#tile description#> *  @param image       <#image description#> *  @param selectImage <#selectImage description#> */-(void)setTabbarController:(UIViewController *)childVC Title:(NSString *)tile image:(NSString *)image selectImage: (NSString *)selectImage{//    childVC.title  =tile;//    childVC.tabBarItem.image = [UIImage imageNamed:image];//    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];    childVC.view.backgroundColor = CSRandomColor;    childVC.tabBarItem.title = tile;    childVC.tabBarItem.image = [UIImage imageNamed:image];    childVC.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];    [self addChildViewController:childVC];        CSNavigationViewController *myNav =[[CSNavigationViewController alloc]initWithRootViewController:childVC];    [self addChildViewController:myNav];}

 

通過重構nav中的push方法來判斷對應的資料:判斷通過push的viewcontroller是不是存在,count>0將隱藏對應的tabbar

/** *  攔截push進來的視圖 * */-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{    if (self.viewControllers.count>0) {   //如果push進來的不是棧底控制器的話        viewController.hidesBottomBarWhenPushed = YES;    }    [super pushViewController:viewController animated:YES];}

 

 

給對應的子視圖設定對應的偽資料,並且做好相應的點擊時間的跳轉:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {#warning Incomplete method implementation.    // Return the number of rows in the section.    return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    static NSString * ID = @"cell";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID ];        if (!cell) {        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];    }    cell.textLabel.text = [NSString stringWithFormat:@"我是第 %ld",(long)indexPath.row];    return cell;}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    UIViewController *myView = [[UIViewController alloc]init];    myView.view.backgroundColor = [UIColor redColor];    myView.title = @"diary跳轉";    [self.navigationController pushViewController:myView animated:YES];}

 

對應頂部的UIBarButtonItem的點擊,建立對應UIBarButtonItem的分類

//重構代碼實現點擊    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_friendsearch" highImage:@"navigationbar_friendsearch_highlighted" target:self action:@selector(pop)];-(void)pop{    UIViewController *aboutView = [[UIViewController alloc]init];    [aboutView.view setBackgroundColor:[UIColor redColor]];    [self.navigationController pushViewController:aboutView animated:YES];}

分類中對應的代碼:

+(UIBarButtonItem *)itemWithImage:(NSString *)imageName highImage:(NSString *)highImage target:(id)target action:(SEL)action{    UIButton *button = [[UIButton alloc]init];//    button  setImage:imageName forState:<#(UIControlState)#>    [button   setBackgroundImage:[UIImage imageNamed:imageName ] forState:UIControlStateNormal];    [button setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];    //    button.frame.size = button.currentBackgroundImage.size;    CGRect frame = button.frame;    frame.size = button.currentBackgroundImage.size;    button.frame = frame;        [button   addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

代碼搭建記事本架構(一)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.