How to pass data from one view to another view in iphone [duplicate]

蓝咒 提交于 2019-12-22 01:22:47

问题


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.


回答1:


  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!!




回答2:


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

and call

[logInView doSomeThing:yourDetails];

after

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




回答3:


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];


来源:https://stackoverflow.com/questions/15401852/how-to-pass-data-from-one-view-to-another-view-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!