UI23_显示侧边栏(LeftSlideViewController)

侧边栏主要是app的功能

显示的效果和过程

点击左上角的按钮,左边弹出左边视图.再点击收回左边视图.
我们在当前的UIViewController中的导航栏navigationItem上创建左边按钮的点击的效果.然后在点击方法填写回到主window的代码和转换关闭开启视图的状态.而左视图的内容部分我们用另一个UIViewController显示

左视图内容的代码部分

**在.m文件中**
**1.定义两个属性**
  **用于铺左视图的界面**
   @property (nonatomic, retain)UITableView *tableView;
  **用于显示左视图的内容**
   @property (nonatomic, retain)NSMutableArray *mArr;
**2.设置数组部分**
   self.mArr = [@[@"我的攻略", @"我的单品", @"我的案例", @"清除缓存", @"一键换肤", @"关于我们"]mutableCopy];
**3.界面设置部分**
  **用UITableView实现**
  **要用Grouped   使自己造的section随着分割线取消  而看不到   视觉上  给上留出上面的header位置**
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableView];  
**4.TableView的协议实现部分**
    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 120;
}
   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _mArr.count;
}
   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *cellID = @"cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
   if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
   cell.textLabel.text = _mArr[indexPath.row];
   return cell;
} 

导航栏的左边按钮的点击部分

**1.显示左边按钮**
  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"点击" style:UIBarButtonItemStylePlain target:self action:@selector(btn1)];
**2.左边方法实现部分**
  - (void)btn1
{
   **// 通过app 回到主Window用来显示抽屉的VC**
   AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
   **// 由关闭状态打开抽屉**
   if (tempAppDelegate.LeftSlideVC.closed)
    {
        [tempAppDelegate.LeftSlideVC openLeftView];
    }
    **// 关闭抽屉**
    else
    {
        [tempAppDelegate.LeftSlideVC closeLeftView];
    }
}

3.主window实现部分

**(1)单独创建的VC  作为抽屉的View**
    CViewController *cVC = [[CViewController alloc]init];
self.LeftSlideVC = [[LeftSlideViewController alloc] initWithLeftView:cVC andMainView:_tabBar];
    _tabBar是正常的切换ViewController显示栏的部分
**(2)把标签控制器设置为根视图控制器**
    self.window.rootViewController = self.LeftSlideVC
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值