iOS xib&storyboard

简单的各种情况之间的跳转:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    [self.tableView registerClass:[FirstTableViewCell class]forCellReuseIdentifier:@"wgjcell"];//纯代码,cellForRow中无IndexPath时用

    
    //1.在tableView里面放进一个cell,在外面创建一个空壳,把属性拉倒空壳里面,然后在cellForRow里面直接取出使用(storyBoard性质的创建)
//    //2.创建cell的时候自带一个xib(或者创建cell后,在建xib,然后做关联操作)
//        UINib *nib = [UINib nibWithNibName:@"SecondTableViewCell" bundle:[NSBundle mainBundle]];
//        [self.tableView registerNib:nib forCellReuseIdentifier:@"secondCell"]; //注册一个nib文件

}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.accountText.text = @"有没有";
    self.passwordText.text = @"密码真的有";

}


#pragma mark - UITableView datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 50;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    //1.
    static NSString *strIndentifier = @"wgjcell";//标示和stroyBoard里面cell的标示一样
    FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strIndentifier forIndexPath:indexPath];
    cell.firstLabel.text = @"产品名称";
    if (indexPath.row % 2 == 0) {
        cell.firstLabel.text = @"不一样的字";
    }
      return cell;
    //2.
//    SecondTableViewCell *secondCell = [tableView dequeueReusableCellWithIdentifier:@"secondCell" forIndexPath:indexPath];
//    secondCell.firstLabel.text = @"中间first";
//    NSLog(@"wgj:%ld %@",indexPath.row,[NSString stringWithFormat:@"%lld",&secondCell]);
//    return secondCell;
 
    
  
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
- (IBAction)daimaJump:(id)sender {
    
    [self performSegueWithIdentifier:@"lineJump" sender:self];
}

//通过线跳转会执行一个方法
//这个方法会在使用segue进行跳转的时候执行
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"跳到页面");
    //Segue可以有很多,跳转的时候都会执行这个方法,我们可以通过判断Segue的标识,来断定它是哪一个
    if ([segue.identifier isEqualToString:@"lineJump"])
    {
        //通过Segue的destinationViewController属性,可以获取到将要跳转到的controller
        LineJumpTableViewController *lineVC = segue.destinationViewController;
        lineVC.txtStr = @"333有值吗";

    }
}

- (IBAction)sameBoardJump:(UIButton *)sender {
    
    //想要使用StoryBoard里面的Controller就要先获取到这个StoryBoard,然后通过StoryBoard里面的Controller的标识来获取到这个Controller,不能使用alloc。
    
    //通过StoryBoard的名字来获取到StoryBoard
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
    //通过标识获取StoryBoard里面的Controller
    SameBoardNoLineVC *sec = [mainStoryBoard instantiateViewControllerWithIdentifier:@"sameBoardVC"];
    
    //当创建一个controller的时候,如果没有显示这个controller的界面,那么这个controller的view就不会加载(controller的view是懒加载),就不执行loadView、viewDidLoad等方法,所以在传值的时候要注意先后顺序。
//        NSLog(@"%@",sec.view); //不写getter方法的话,就在sec初始化方法中动手脚。
    sec.label.text = @"赋值了";
    
    [self.navigationController pushViewController:sec animated:YES];
//    [self presentViewController:sec animated:YES completion:nil];
    
    
    //    - (id)instantiateInitialViewController;这个方法是返回入口的controller。
    
    
}


- (IBAction)nextStoryboardJump:(UIButton *)sender {
    
    UIStoryboard *MyStoryBoard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:[NSBundle mainBundle]];
    UIViewController *myS = [MyStoryBoard instantiateViewControllerWithIdentifier:@"MyStoryb"];
    [self.navigationController pushViewController:myS animated:YES];

}



@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文Demo环境:Xcode 7.2.1 随着苹果设备尺寸越来越多,使用Xib、Storyboard + Auto...
    iOS_永宝阅读 6,100评论 17 34
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,638评论 25 708
  • 写在前面 我不算是个资深码农,有些iOS的编程经验。希望找到一种高效的方式来创作出自己的iOS应用。大家都知道纯代...
    五九楼阅读 14,551评论 3 40
  • 原文:子曰:“学而不思则罔,思而不学则殆。” 此篇论学与思。 孔子讲:“学习的时候不思考容易被知识迷惑,只思考不学...
    哈皮波阅读 982评论 0 0
  • 晚上和一帮人一起去食堂吃饭,在路上边走边聊。 M问我:“你家是不是在丽水?” “是啊。”我说 “我寝室里买了一把拖...
    李旭洋阅读 262评论 0 1