Passing variables from one view to an other

前端 未结 2 837
面向向阳花
面向向阳花 2021-01-17 02:09

I know this question as been asked over and over but it\'s still quite obscure to me, so I guess making an example with my code instead will probably be easier .

I k

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-17 02:18

    By creating a @property called evTe or whatever in both view controllers.

    If the FirstViewController is responsible for creating the SecondViewController you could store the value of evTe in a property in FirstViewController and then after you have created the SecondViewController you set the evTe property there as well.

    - (IBAction) makeKeyboardGoAway;
    {
        [Te resignFirstResponder];  
        self.evTe = [Te.text integerValue];
    }
    

    // other method where SecondViewController is created

    SecondViewController* second = [[SecondViewController alloc] init];
    second.evTe = self.evTe;
    // do what ever
    

    --Edit--

    @interface FirstViewController : UIViewController {
    
        IBOutlet UITextField *Te;
        NSInteger evTe;
    
    }
    
    @property (nonatomic, retain) UITextField *Te;
    @property (nonatomic) NSInteger evTe;
    

提交回复
热议问题