问题
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:
- Create a variable for your passing data into your next view.
- Using an instance of the next view, access the variable that you have created in next view
- assign your value to the variable
For Ex in your case;
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];
- 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