待辦事項不要使用presentViewController
來引入登錄控制器。 完整過程: 單身類。設置一個全球性財產。
@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];
}
這是補充te過程。
你的過程是錯誤的 – user3182143
這是一個答案? – samir
你正在做錯誤的執行 – user3182143