How to pass data from one view to another view in

2019-04-17 16:45发布

I want to pass int or string data from one view to another, please help me

NSUInteger i1 = [array indexOfObject:username];
SSPUserLogedInViewController *logInView = [[SSPUserLogedInViewController alloc] init];
logInView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:logInView animated:YES completion:nil];

I am able to next view but not able to pass the data. Thanks in advance.

3条回答
甜甜的少女心
2楼-- · 2019-04-17 17:14
  1. Create a variable for your passing data into your next view.
  2. Using an instance of the next view, access the variable that you have created in next view
  3. assign your value to the variable

For Ex in your case;

  1. Suppose you want to pass the value of an int

    In Next view controller: copy this in **.h** file

@property (assign) int temp;

2. SSPUserLogedInViewController *logInView = [[SSPUserLogedInViewController alloc] init]; >

    logInView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        logInView.temp = <YOUR_VALUE>
        [self presentViewController:logInView animated:YES completion:nil];
  1. In Next view controller: copy this in **.m** file

-(void)viewWillAppear

{

   NSLog(@"My Value = %i",_temp);

}

Enjoy Programming!!

查看更多
在下西门庆
3楼-- · 2019-04-17 17:33

Write some function like - (void)doSomeThing:(NSString) data in yourSSPUserLogedInViewController class

and call

[logInView doSomeThing:yourDetails];

after

SSPUserLogedInViewController *logInView = [[SSPUserLogedInViewController alloc] init];

查看更多
ら.Afraid
4楼-- · 2019-04-17 17:33

define NSMutableString *string; with property in the SSPUserLogedInViewController class. alloc init in view did load. You can set string like this.

NSString *i1 = [NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.row]];
SSPUserLogedInViewController *logInView = [[SSPUserLogedInViewController alloc] init];
[logInView.string setString:i1];
logInView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:logInView animated:YES completion:nil];
查看更多
登录 后发表回答