2015-12-08 38 views
1

這是一個正常的LoginView調用特定的動作在我的應用隱藏LoginViewController或者解聘到parentView

sourceViewVontroller

if ([password length] == 0) { 

    loginViewController *seatView = [mainStory instantiateViewControllerWithIdentifier:@"loggingView"]; 



    [self presentViewController:login animated:YES completion:nil]; 

} 

它檢查時,他的調用這個動作,如果用戶沒有在尚未簽署,因此它他重定向到loginViewController,然後

loginViewController

UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

DestinationViewController *Dest = [mainStory instantiateViewControllerWithIdentifier:@"destView"]; 


[self presentViewController:Dest animated:YES completion:nil]; 

它去到需要登錄的destinationView,現在我的問題是如何返回(關閉不presentmodalView)到sourceViewController,或者簡單地說,如何在成功時從隊列中移除loginViewController並直接關閉源代碼?

destinationViewController

// 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

你的過程是錯誤的 – user3182143

+0

這是一個答案? – samir

+0

你正在做錯誤的執行 – user3182143

回答

0

待辦事項不要使用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過程。

+0

真棒,非常感謝這個完整的答案,已經嘗試過,它的作品! – samir

+0

@samir - 如果它的工作正常,那麼請把我的答案投給我。 –

+0

試圖這樣做兄弟,但仍然沒有15聲望投票:S – samir

1

我建議你另一種方式:

首先在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

您將檢查用戶登錄與否。如果登錄,您將設置rootViewdestinationViewController。如果沒有設置rootViewloginViewController

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; 
} 

註銷時你只需要調用notificationdelegate設置的windowrootViewControllerloginViewController

0

使用開卷塞格斯

添加在SourceViewController

的方法對於斯威夫特

@IBAction func unwindToThisViewController(segue: UIStoryboardSegue) { 

} 

對於Objective-C的

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue { 

} 

你可以回來的SourceViewController在兩種方式。

  1. 使用Storyboard e.g當UIButton動作火災。
  2. 在代碼中使用performSegueWithIdentifier

故事板:

控制拖動形成DestinationViewController一個UIButtonExit賽格瑞在SourceViewController

enter image description here

在編碼:

  1. 控制拖動形成DestinationViewController一個UIButtonExit賽格瑞在SourceViewController

enter image description here

  • 呼叫performSegueWithIdentifier:@"ExitToSourceViewController"當需要回來SourceViewController