这是正常的LoginView调用我的应用程序中的特定操作
if ([password length] == 0) {
loginViewController *seatView = [mainStory instantiateViewControllerWithIdentifier:@"loggingView"];
[self presentViewController:login animated:YES completion:nil];
}
它检查用户在调用此操作时是否尚未登录,因此将其重定向到loginViewController,然后
UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DestinationViewController *Dest = [mainStory instantiateViewControllerWithIdentifier:@"destView"];
[self presentViewController:Dest animated:YES completion:nil];
它转到需要登录的destinationView,现在我的问题是如何返回(关闭not presentmodalView)到sourceViewController,或者简单地说,如何在成功时从队列中删除loginViewController并直接关闭源?
// Tried to use presentView .. but i dont need to reload sourceView, just dismiss to it !
//[self presentViewController:srcView animated:YES completion:NULL];
//This is what am doing ..
[self dismissViewControllerAnimated:NO completion:nil];
或者只是让我知道是否有其他专业方法来执行此登录流程
答案 0 :(得分:1)
我建议你另辟蹊径:
首先在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
您将检查用户是否登录。如果登录,您会将rootView
设置为destinationViewController
。如果未将rootView
设置为loginViewController
SampleCode:
UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
if (logged) {
DestinationViewController *Dest = [mainStory instantiateViewControllerWithIdentifier:@"destView"];
self.window.rootViewController = Dest;
} else {
LoginViewController *seatView = [mainStory instantiateViewControllerWithIdentifier:@"loggingView"];
self.window.rootViewController = seatView;
}
退出时,您只需致电notification
或delegate
将rootViewController
的{{1}}设为window
。
答案 1 :(得分:0)
使用展开细分
在SourceViewController
对于Swift
@IBAction func unwindToThisViewController(segue: UIStoryboardSegue) {
}
对于Objective-C
- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue {
}
您可以通过两种方式返回SourceViewController
。
Storyboard
,例如,当UIButton
操作触发时。performSegueWithIdentifier
。<强>故事板:强>
通过UIButton
DestinationViewController
到Exit
segue中的SourceViewController
控制拖动
代码:
答案 2 :(得分:0)
请勿使用presentViewController
来启动登录控制器。
完整流程:
在Singleton类中。设置全局属性。
@property (assign)BOOL isUserLoggedIn;
当用户登录或注销时,请将此变量设置为true或false。
在LoginViewController中设置枚举。
typedef enum {
DestViewControllerOne =1,
DestViewControllerTwo
} SignInType;
在此枚举中,将所有视图控制器放在要进行登录检查的位置。 在登录视图控制器中设置属性以保存源控制器值 -
@property (nonatomic, assign) NSInteger signInType;
在登录控制器中设置委托以在成功登录后重定向 -
@protocol SignInProtocolDelegate <NSObject>
@optional
-(void) signInSuccess:(NSInteger) signInType;
@end
在登录控制器中使用该委托创建属性 -
@property (nonatomic, assign) NSObject<SignInProtocolDelegate>* delegate;
现在,在继续执行所需的视图控制器之前,请执行以下检查 -
if(![[TESingleton shareData] isUserLoggedIn]){
[self funcNavigateToSignInWithAlert:YES withSignInType:proceedToDestViewControllerOne];
}
else
{
[self proceedToDestViewControllerOne];
}
-(void)funcNavigateToSignInWithAlert:(BOOL)showAlert withSignInType:(NSInteger) signIntype
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:STORYBOARDNAME bundle:nil];
LoginViewController *viewController = (LoginViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[viewController setSignInType:signIntype];
[viewController setDelegate:self];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[[SlideNavigationController sharedInstance] presentViewController:navController animated:YES completion:nil];
}
这样,它将带来登录页面。
下一步 - 成功登录后,在登录控制器中执行此操作:
[self dismissViewControllerAnimated:YES completion:nil];
[[self delegate] signInSuccess:self.signInType];
在我们上面写的源控制器中导入登录委托方法 -
-(void) signInSuccess:(NSInteger) signInType
{
switch (signInType)
{
case DestViewControllerOne:
[self performSelector:@selector(proceedToDestViewControllerOne) withObject:nil afterDelay:0.5];
break;
case DestViewControllerTwo:
[self performSelector:@selector(proceedToDestViewControllerTwo) withObject:nil afterDelay:0.5];
break;
default:
break;
}
}
在源视图控制器中实现这些方法 -
-(void) proceedToDestViewControllerOne
{
//Restricting navigation to signin
//Addded by vikas Jul 8,2015
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:STORYBOARDNAME bundle:nil];
DestViewcontrollerOne *objDestViewcontrollerOne = (DestViewcontrollerOne *)[storyboard instantiateViewControllerWithIdentifier:@"DestViewcontrollerOne"];
[self.navigationController objDestViewcontrollerOne animated:YES];
}
这是一个完整的过程。