Show rootview controller after press logut?
My case is having two login and both will have a left menu,everything ok. I have loaded menu content based on the user login and store it in nsuserdefalut. Here i want to know,how to switch to Home screen and start a menu newly.
also i refered issue no:105,that is not help me...
i have used code like below
-
(void)viewDidLoad { [super viewDidLoad];
userInfo = [NSUserDefaults standardUserDefaults]; isCheckUserORProvider=[userInfo valueForKey:@"UserType"]; if ([isCheckUserORProvider isEqualToString:@"Provider"]) { self.menuArray = @[@"Profile", @"Help", @"Jobs",@"Logout"]; self.imageArray=[[NSArray alloc]initWithObjects:@"menu_profile_icon_normal.png",@"info_icon_normal.png",@"jobs_menu_icon_normal.png",@"", nil]; self.imageActiveArray=[[NSArray alloc]initWithObjects:@"menu_profile_icon_active.png",@"info_icon_active.png",@"jobs_menu_icon_active.png",@"", nil];
NSURL *urlString=[NSURL URLWithString:[NSString stringWithFormat:@"http://guruzilla.azurewebsites.net/user/GetUsers?UserId=%@",[userInfo valueForKey:@"UserLoginId"]]]; NSLog(@"URL------>%@",urlString); NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlString cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; AFHTTPRequestOperation *requestObj = [[AFHTTPRequestOperation alloc] initWithRequest:request]; requestObj.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments]; [requestObj setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Response------->\n\n%@", responseObject); name=[NSString stringWithFormat:@"%@ %@",[responseObject valueForKey:@"UserFirstName"],[responseObject valueForKey:@"UserLastname"]]; email=[NSString stringWithFormat:@"%@",[responseObject valueForKey:@"UserEmail"]]; [self.menuTableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", [error localizedDescription]); }]; [requestObj start];} else { self.menuArray = @[@"Profile", @"Help", @"Jobs",@"New",@"Favorites",@"Logout"]; self.imageArray=[[NSArray alloc]initWithObjects:@"menu_profile_icon_normal.png",@"info_icon_normal.png",@"jobs_menu_icon_normal.png",@"addnew_menu_icon_normal",@"fav_icon_normal",@"",nil]; self.imageActiveArray=[[NSArray alloc]initWithObjects:@"menu_profile_icon_active.png",@"info_icon_active.png",@"jobs_menu_icon_active.png",@"addnew_menu_icon_active",@"fav_icon_active",@"",nil]; NSString *urlStr=[kGET_PROVIDER_DETAIL_URL stringByAppendingString:[userInfo valueForKey:@"LoginId"]];; NSURL *urlString=[NSURL URLWithString:urlStr]; NSLog(@"URL------>%@",urlString); NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlString cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *requestObj = [[AFHTTPRequestOperation alloc] initWithRequest:request]; requestObj.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments]; [requestObj setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Response------->\n\n%@", responseObject); name=[NSString stringWithFormat:@"%@ %@",[responseObject valueForKey:@"ProviderFirstName"],[responseObject valueForKey:@"ProviderLastName"]]; email=[NSString stringWithFormat:@"%@",[responseObject valueForKey:@"ProviderEmail"]]; [self.menuTableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", [error localizedDescription]); }]; [requestObj start];}
self.menuTableView.delegate=self; self.menuTableView.dataSource=self;
// Do any additional setup after loading the view. }
-
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 2; }
pragma mark - TableView Delegate Methods
-
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section==0) { return 1; } else { return [menuArray count];
} }
-
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section==0) { profileCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([profileCell class])]; cell.profileImage.layer.cornerRadius = cell.profileImage.frame.size.width / 2; cell.profileImage.layer.masksToBounds = YES; cell.profileImage.layer.borderWidth = 2; cell.contentView.backgroundColor=[UIColor orangeColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.profileImage.image=[UIImage imageNamed:@"menu_profile_icon_normal.PNG"]; cell.nameLbl.text=name; cell.emailLbl.text=email; return cell;
} else { labelCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([labelCell class])]; [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; cell.contentView.backgroundColor=[UIColor whiteColor];
cell.menuTitleLbl.text = [menuArray objectAtIndex:indexPath.row]; cell.imageView.image=[UIImage imageNamed:[self.imageArray objectAtIndex:indexPath.row]]; if ([isCheckUserORProvider isEqualToString:@"Provider"]) { if (indexPath.row==3) { cell.imageView.hidden=YES; cell.menuTitleLbl.textColor=[UIColor orangeColor]; } } else { if (indexPath.row==5) { cell.imageView.hidden=YES; cell.menuTitleLbl.textColor=[UIColor orangeColor]; } } return cell;}
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section==0) { return 170; } else { return 60; } }
-
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section==0) { [tableView deselectRowAtIndexPath:indexPath animated:YES]; } else { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
if (indexPath.row==0) { UserProfileController *initalViewController=[mainStoryboard instantiateViewControllerWithIdentifier:@"UserProfileControllerID"]; [self.navigationController pushViewController:initalViewController animated:YES]; //[[SlideNavigationController sharedInstance]setAvoidSwitchingToSameClassViewController:NO]; [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:initalViewController withSlideOutAnimation:NO andCompletion:nil]; } else if(indexPath.row==1) { HelpController *initalViewController=[mainStoryboard instantiateViewControllerWithIdentifier:@"HelpControllerID"]; [self.navigationController pushViewController:initalViewController animated:YES]; //[[SlideNavigationController sharedInstance]setAvoidSwitchingToSameClassViewController:NO]; [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:initalViewController withSlideOutAnimation:NO andCompletion:nil]; } else if(indexPath.row==2) { JobStatusListController *initalViewController=[mainStoryboard instantiateViewControllerWithIdentifier:@"JobStatusListController"]; [self.navigationController pushViewController:initalViewController animated:YES]; //[[SlideNavigationController sharedInstance]setAvoidSwitchingToSameClassViewController:NO]; [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:initalViewController withSlideOutAnimation:NO andCompletion:nil]; } if ([isCheckUserORProvider isEqualToString:@"Provider"]) { if(indexPath.row==3) { //do logout code for user login [[SlideNavigationController sharedInstance]closeMenuWithCompletion:^{ }]; } } else { if(indexPath.row==3) { ChooseServiceController *initalViewController=[mainStoryboard instantiateViewControllerWithIdentifier:@"ChooseServiceControllerID"]; [self.navigationController pushViewController:initalViewController animated:YES]; // [[SlideNavigationController sharedInstance]setAvoidSwitchingToSameClassViewController:NO]; [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:initalViewController withSlideOutAnimation:NO andCompletion:nil]; } else if(indexPath.row==4) { FavoriteController *initalViewController=[mainStoryboard instantiateViewControllerWithIdentifier:@"FavoriteController"]; [self.navigationController pushViewController:initalViewController animated:YES]; // [[SlideNavigationController sharedInstance]setAvoidSwitchingToSameClassViewController:NO]; [[SlideNavigationController sharedInstance] popToRootAndSwitchToViewController:initalViewController withSlideOutAnimation:NO andCompletion:nil]; } else if(indexPath.row==5) { //do logout code for provider login } }} }
solved this Issue?