使用storyboard 中跳转到自定义xib中实现
2015-10-30 11:22
375 查看
布局:在storyboard中拖入Navigation Controller 控制器,默认后面是tableview,为了使用能自定义tableview.需要新建类继承与uitableviewcontrolle
的Tableviewcontroller,然后在storyboard中指定tableview控制器使用新建的类Tableviewcontroller,可以在新建的Tableviwcontroller.m中来自定义tableview
以项目Music为例
为了使点击每个cell跳转到相同的xib中
需新建类和xib,继承于uiviewcontroller,为playingviewcontroller
由于上面使用show显示xib里面内容,需在playingviewcontroller.h中新建一个方法
-(void)show;
在playingviewcontroller.m中实现即可
的Tableviewcontroller,然后在storyboard中指定tableview控制器使用新建的类Tableviewcontroller,可以在新建的Tableviwcontroller.m中来自定义tableview
以项目Music为例
#import "TableViewController.h" #import "MJExtension.h" #import "MUsic.h" #import "PlayingViewController.h" @interface TableViewController () @property(strong,nonatomic)NSArray *musics; @property(strong,nonatomic)PlayingViewController *playingnv; @end @implementation TableViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.musics.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"22222222"); static NSString *ID=@"music"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:ID]; if(!cell){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } MUsic *music=self.musics[indexPath.row]; cell.imageView.image=[UIImage imageNamed:music.singerIcon]; cell.textLabel.text=music.name; cell.detailTextLabel.text=music.singer; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.playingnv show]; } -(NSArray *)musics { if (!_musics) { _musics=[MUsic objectArrayWithFilename:@"Musics.plist"]; } return _musics; } -(PlayingViewController *)playingnv { if (!_playingnv) { self.playingnv=[[PlayingViewController alloc]init]; } return _playingnv; } @end
为了使点击每个cell跳转到相同的xib中
需新建类和xib,继承于uiviewcontroller,为playingviewcontroller
由于上面使用show显示xib里面内容,需在playingviewcontroller.h中新建一个方法
-(void)show;
在playingviewcontroller.m中实现即可
#import "PlayingViewController.h" #import "UIView+Extension.h" @interface PlayingViewController () @end @implementation PlayingViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } -(void)show { // 1. 拿到Window UIWindow *window = [UIApplication sharedApplication].keyWindow; // 2. 设置当前控制器的frame self.view.frame = window.bounds; // 3. 将当前控制器的view添加到Window上 [window addSubview:self.view]; self.view.hidden = NO; // 禁用交互功能 window.userInteractionEnabled = NO; // 4.执行动画, 让控制器的view从下面转出来 self.view.y = window.bounds.size.height; [UIView animateWithDuration:1 animations:^{ // 执行动画 self.view.y = 0; } completion:^(BOOL finished) { // 开启交互 window.userInteractionEnabled = YES; }]; }; @end
相关文章推荐
- javascript 学习总结(七)String对象
- register 不允许 block 模式,而默认的是
- 水波浪型的进度加载器
- JavaScript传参的问题
- Ubuntu 固定IP设置
- Lua篇(第02章):Demo讲解之Lua和C++牵手
- 如何正确选择uiimage之间不同的过滤器(gpuimage)
- 网络游戏架构与微服务架构简单对比
- 基于h5的图片无刷新上传(uploadifive)
- WinGW安装
- maven_spring_cxf
- Mysql 5.6 配置(备忘)
- hadoop生态系统组件目前的理解(先记录,有些地方理解不正确,后面修改)
- [Java并发包学习九]Java中的阻塞队列
- PHP数组之array_values
- 获取sd卡路径
- Linux必备技能:vi的使用
- ajax与nodejs实现小交互(html,txt)
- ios 实现 cell 的动态高度
- 12位资深医生的健康秘笈