UI23_显示侧边栏(LeftSlideViewController)
2015-08-29 18:09
399 查看
侧边栏主要是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
相关文章推荐
- UI控件--推送,以及Block块
- UI手势二
- UI手势
- UI中的控件简介
- UI 19 数据库
- ICPC 7096 A Rational Sequence
- UITextView根据键盘自适应边框
- iOS UILabel两端对齐的实现(可包括中英文/数字)
- UGUI之Canvas(画布)
- 08 java.lang.ProcessBuilder
- UGUI简述
- UIDevice通知
- UILabel的宽度自适应文字
- 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记45 Embed Segues
- UI 18 单例
- UI 18 UICollectionView
- 实现自适应的UI界面
- UIPageControl, UIScrollView属性及UIScrollViewDelegate详解
- IOS UICollectionView
- 1041. Be Unique (20)