美文网首页
iOS xib&storyboard

iOS xib&storyboard

作者: 草原烈鹰 | 来源:发表于2017-01-13 15:01 被阅读21次
    简单的各种情况之间的跳转:
    
    - (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
    
    

    相关文章

      网友评论

          本文标题:iOS xib&storyboard

          本文链接:https://www.haomeiwen.com/subject/mjdsbttx.html