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
  • 相关阅读:
    JDA 8.0.0.0小版本升级
    Mybatis中的resultType和resultMap
    FP硬绑
    消息 14607,级别 16,状态 1,过程 sp_send_dbmail,第 141 行 profile 名称无效
    检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a 因为配置标识不正确,系统无法开始服务器进程。请检查用户名和密码。 (异常来自 HRESULT:0x8000401A)。 在 BatchImportEntryTable.GetExcelData(String FileName)
    工单重复回写
    ORACLE 对一个表进行循环查数,再根据MO供给数量写入另一个新表
    siebel切换数据源
    MYSQL TIMESTAMP with implicit DEFAULT value is deprecated.
    多账户的统一登录 (转)
  • 原文地址:https://www.cnblogs.com/wohaoxue/p/4805636.html
Copyright © 2011-2022 走看看