zoukankan      html  css  js  c++  java
  • iOS中的视图跳转的三种方式(代码跳转,根据桥跳转,按钮跳转)

    #import "ViewController.h"
    #import "SecondViewController.h"
    @interface ViewController ()
    @property (retain, nonatomic) IBOutlet UITextField *textField;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    - (IBAction)pushButtonAction:(id)sender {
        
        //跳转第一种方式
    //    SecondViewController *secondVC = [[SecondViewController alloc] init];
    //    [self.navigationController pushViewController:secondVC animated:YES];
        //1.当要获取的视图控制器对象和当前视图控制器在同一个storyboard文件中
        //从 storyboard 获取对应的视图控制器对象
        //self.storyboard 获取当前视图控制器所在的 storyboard对象
        /*
       SecondViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"second"];
        [self.navigationController pushViewController:secondVC animated:YES];
          //2.当要获取的视图控制器对象和当前视图控制器在同一个storyboard文件中
        //1.先创建storyboard对象
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Leo" bundle:nil];
         
         
         
        //假设,另外一个storyboard的名字是Leo.stroyboard
        //(2)从对应的storyboard中根据标识符,获取视图控制器对象
        SecondViewController *second = [storyboard instantiateViewControllerWithIdentifier:@"reuse"];
        //然后再push 即可
         */
        //跳转第二种,根据桥跳转
        //[self performSegueWithIdentifier:@"reuse" sender:nil];
        
        
        //跳转第三种方式
        //直接将按钮与下一个界面建桥即可,不用写任何代码,但是该方法只有一个弊端,因为这种方法为单个按钮单独定制的跳转,如果一个界面中有多个按钮都要跳转到这一个界面,还需要增加多个桥,这样的话,关系非常的冗杂,不如直接通过第二种方式(视图控制器与视图控制器之间建桥,让多个button点击方法实现跳转即可)
        
    }
    //通过桥(segue)完成页面的跳转,在跳转之前该方法就会出触发,一般用于传值.
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        //获取下个界面的对象
       SecondViewController *secondVC = segue.destinationViewController;
        //传值
        secondVC.data = self.textField.text;
        
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)dealloc {
        [_textField release];
        [super dealloc];
    }
    @end
    SecondViewController.h
    
    #import <UIKit/UIKit.h>
    
    @interface SecondViewController : UIViewController
    @property (nonatomic, copy) NSString *data;
    @end
    
    
    SecondViewController.m
    
    #import "SecondViewController.h"
    
    @interface SecondViewController ()
    @property (retain, nonatomic) IBOutlet UILabel *aLable;
    
    @end
    
    @implementation SecondViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.aLable.text = self.data;
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    - (void)dealloc {
        [_aLable release];
        self.data = nil;
        [super dealloc];
    }
    @end
  • 相关阅读:
    将数组转换为 List, 使用 Collections.addAll(arrayList, array)
    Numpy学习笔记
    sql 批量修改字段内容
    sql 查询的优化
    选择低薪喜欢的工作, 还是高薪不喜欢的工作 ?
    Tornado + Bootstrap 快速搭建自己的web应用
    sql查询出现次数最多的记录的名称和现次数以及QT聚合查找失败解决
    idea中修改git提交代码的用户名
    初识Spring Cloud与微服务
    微信小程序解析富文本的几种方法
  • 原文地址:https://www.cnblogs.com/wohaoxue/p/4805636.html
Copyright © 2011-2022 走看看