I have a set of code that parses an XML file to find a user ID number. This ID number is sent to another view controller for a SOAP WSDL request. The problem is that the value is never set.
My two classes are LoginPageViewController and EMIMenuTableViewController.
I am trying to pass an integer value from LoginPageViewController to EMIMenuTableViewController.
Here is the header file for EMIMenuTableViewController:
#import <UIKit/UIKit.h>
@interface EMIMenuTableViewController : UITableViewController
@property (nonatomic) int userNumber;
@end
Here is the header file for LoginPageViewController:
#import <UIKit/UIKit.h>
@interface LoginPageViewController : UIViewController <NSXMLParserDelegate>
{
NSXMLParser *xmlparser;
NSString *classelement;
NSMutableArray *titarry;
NSMutableArray *linkarray;
bool itemselected;
NSMutableString *mutttitle;
NSMutableString *mutstrlink;
int userNumber;
NSString *parsedString;
}
// Username and password text fields
@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
// Logging in and registering
- (IBAction)loginButtonSelected:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
// Unwind segue IBAction for logging out
- (IBAction)logoutAndUnwind:(UIStoryboardSegue *)segue;
@end
Here is where the value is set in LoginPageViewController:
- (void)parserDidEndDocument:(nonnull NSXMLParser *)parser {
EMIMenuTableViewController *controller = [[EMIMenuTableViewController alloc] init];
// If the user is authenticated, allow them to proceed with the segue
if([parsedString containsString:@"User Authenticated"]) {
>>>controller.userNumber = userNumber<<<; - set here
NSLog(@"User:%d", userNumber);
[self performSegueWithIdentifier:@"login_success" sender:self];
NSLog(@"Logged In");
// If the server says that the user isn't found, notify the user to create an account.
} else if([parsedString containsString:@"User Not Found"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"User Not Found" message:@"Please create an account!" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
[alert show];
// If the server replies that the password is incorrect, notify the user.
} else if([parsedString containsString:@"Password Incorrect"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Incorrect Username/Password" message:@"Plese try again." delegate:self cancelButtonTitle:@"close" otherButtonTitles:nil, nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"An error has occurred!" message:@"Please check your network connection and try again." delegate:self cancelButtonTitle:@"close" otherButtonTitles:nil, nil];
[alert show];
}
}
Here is the code that shows that the value isn't being set (this is in EMIMenuTableViewController):
NSLog(@"User: %d", _userNumber);
Also, here is the console output. You can see that the value is set in LoginPageViewController where I logged it, but when it is logged in EMIMenuTableViewController, it is 0.
2015-07-08 15:09:41.151 EMI[1971:173596] User:27808
2015-07-08 15:09:41.179 EMI[1971:173596] Logged In
2015-07-08 15:09:41.186 EMI[1971:173596] User: 0
I figured I was doing this right, but I can't figure out what is wrong. Am I setting the variable wrong?
Thanks.