I have a parent view controller which loads a child view using presentmodalview. To be precise, this child view is a login page.
The login page has two textfields (email and password) and a 'login' button. When the login button is pressed, providing the data input is valid, I would like to send the user details to the root view controller who will then create a user object if the user exists or otherwise present a uialertview indicating to the user that invalid开发者_StackOverflow中文版 details have been entered.
In my child view I have the following function linked to the 'login button':
-(IBAction) signIn:(NSString*)userEmail with:(NSString*)userPassword{
//takes text field values and instantiates a dbConnector object to
//check to see if user exists - must also post uialertview if user details incorrect
NSString* uName = [email text];
NSString* pword = [password text];
userDetails = [[NSMutableArray alloc] initWithObjects:uName, pword, nil];
NSLog(@"%@", userDetails);
}
What is the best way to pass the userDetails array back to the rootviewcontroller after the button has been pressed?
SOLUTION - Protocols & Delegates
Create UserDeatails array in the ParentViewController and Set its Value when the Button is Pressed in ChildViewController.
But you have to create object of the ParentViewController as like;
ParentViewController *parentView = [[ParentViewController alloc] initWithNibName:@"ParentViewControllerName" bundle:nil ];
parentView.userDeatails = userDetails_in_ChildView;
You need to pass your user object before pushing or present another view controller.
Refer this answer. Hope this help.
Just declare a variable into Your Delegate file like
String *strUsername; String *strPassword;
And also create property and synthesize for that..
then after create a object of your delegate where ever you want like this..
NavigationBarAppDelegate *appDelegate= (NavigationBarAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.strUsername = uName; appDelegate.strPassword = pword;
now this value is get every war..just get it creating delegate object like above...
NavigationBar is a name of my application.
精彩评论