storyboard的应用

226 阅读1分钟
  1. 通过stroyboard id引用页面
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"购物车" bundle:nil];
[self.navigationController pushViewController:[storyBoard instantiateViewControllerWithIdentifier:@"my-test"] animated:YES];
  1. 通过stroyboard 构建tabbar ,并新建类IndexTabBarController,并storyboard的tabbar类,设置为IndexTabBarController,监听事件代理,可改变顶部标题
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    self.navigationItem.title = item.title;
}
  1. 某个页面,不需要顶部导航,则在页面将要显示时,隐藏该导航,将要离开时,要恢复导航
- (void) viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES];
}

-(void) viewWillDisappear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:NO];
}
  1. 解析plist文件
    NSString *path = [[NSBundle mainBundle] pathForResource:@"地址" ofType:@"plist"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
  1. 表格操作
//注册单元格
 [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"reuseIdentifier"];
 
 //使用单元格
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuseIdentifier"];
    }
    cell.textLabel.text = self.data[self.keys[indexPath.section]][indexPath.row];
    return cell;
}