问题
I have FavouriteViewController
in which i have one button on click of button i am presenting a view modally called LoginViewController
(using storyboard).
On this page(LoginViewController
), i again have button, on click of that i am dismissing my modal view controller, after dismissing i again comes back to FavouriteViewController
now on this page when i try to push my view controller it doesn't pushes.
Here is my code snippet,
------ PART 1 -----
FavouriteViewController.m
- (IBAction)LoginClicked:(id)sender {
NSLog(@"--- Navigated to LoginViewController ---");
//Navigates to `LoginViewController` using storyboard..
}
LoginViewController.m
- (IBAction)LoginViaFb:(id)sender{
NSLog(@"--- Inside LoginViafb ---");
[self dismissViewControllerAnimated:YES completion:NULL];
FavoriteTabViewController *fav=[[FavoriteTabViewController alloc] init];
[fav Loginsuccessfull];
}
FavouriteViewController.m
-(void)Loginsuccessfull{
NSLog(@"--- Inside Loginsuccessfull ---");
UserDetailsViewController *user=[[UserDetailsViewController alloc] init];
[self.navigationController pushViewController:user animated:NO];
}
My Log shows:
--- Navigated to LoginViewController ---
--- Inside LoginViafb ---
--- Inside Loginsuccessfull ---
Please help, and thanks in advance.
----- PART 2 -----:
** I also tried:**
Code in my LoginViewController.m
- (IBAction)LoginViaFb:(id)sender{
NSLog(@"--- Inside LoginViafb ---");
[self dismissViewControllerAnimated:YES completion:NULL];
FavoriteTabViewController *fav=[[FavoriteTabViewController alloc] init];
fav.GoLogin=@"some values";
}
and in FavouriteViewController.m
-(void)viewDidAppear:(BOOL)animated{
NSLog(@"some values --- %@",some values);
if ([GoLogin isEqualToString:@"some values"]) {
NSLog(@"Method called");
[self.navigationController pushViewController:[[UserDetailsViewController alloc] init] animated:NO];
}
}
But it still doesn't help, shows some values --- null
回答1:
This is way what I said to you.
FavouriteViewController.m
- (IBAction)LoginClicked:(id)sender {
NSLog(@"--- Navigated to LoginViewController ---");
loginVcObc.logindelegate = self;
}
#pragma mark LoginDelegate
- (void)loginSuccessfull {
UserDetailsViewController *user=[[UserDetailsViewController alloc] init];
[self.navigationController pushViewController:user animated:NO];
}
LoginViewController.h
#import <UIKit/UIKit.h>
@protocol LoginDelegate;
@interface LoginViewController : UIViewController
@property (assign) id <LoginDelegate> logindelegate;
@end
@protocol LoginDelegate <NSObject>
- (void)loginSuccessfull;
@end
LoginViewController.m
#import "LoginViewController.h"
@implementation LoginViewController
@synthesize logindelegate;
- (IBAction)LoginViaFb:(id)sender{
NSLog(@"--- Inside LoginViafb ---");
if (self.logindelegate) {
[self.logindelegate loginSuccessfull];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
来源:https://stackoverflow.com/questions/20259159/unable-to-pushviewcontroller-after-dismissing-present-view-controller