2016-06-21 4 views
0

Swift로 iOS 앱을 제작하는 기본 사항을 배웠습니다. 나는 뭔가를하고 싶지만 그것을 구축하는 방법에 대해서는 잘 모르겠다. 나는 "Home"과 "Account"라는 두 개의 항목으로 된 탭 바 컨트롤러를 가지고있다. 나는 디스플레이에 "계정"을 원하는 : - LoginViewController 사용자가 로그인하지 않은 경우 - UITabBarController에서 ViewController를 바꾸는 방법

내가 어떻게 할 수 있습니다 사용자가

를 기록하는 경우 AccountViewController를? LoginViewController 또는 AccountViewController로 리디렉션하는 ByPassController를 사용하면 어떨까요? 그런 다음 "Account"는 항상 ByPassController를 표시합니다. 하지만 몇 가지 조언을 듣고 싶습니다.

감사합니다.

답변

1

첫째, AccountViewController에 두 번째 탭을 설정합니다. 사용자가 로그인하면 그런 다음, tabBarController:didSelectViewController: 콜백 확인 사용자가 로그인되어 있지 않으면 LoginViewController로의 ViewController를 바꿉니다. 사용자가 로그인 한 후

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    if ([tabBarController selectedIndex] == 1 && !user.isSignedIn) 
    { 
     //fill an array with all the view controllers in the UITabBarController 
     NSMutableArray *arr = [[NSMutableArray alloc] initWithArray:[tabBarController viewControllers]]; 

     //inistantiate login view controller 
     UIViewController *loginViewController = [[LoginViewController] init]; 

     //replace the second UIViewController in the array with LoginViewController 
     [arr replaceObjectAtIndex:1 withObject: loginViewController]; 

     //set array 
     [tabBarController setViewControllers:arr]; 

    } 
} 

와 두 번째 탭을 대체 AccountViewController

1

로그인 상태를 나타내는 부울을 유지할 수 있습니다. 로그인하지 않은 경우보기 필드에 로그인 필드가 표시됩니다.

let loginVC = storyboard.instantiateViewControllerWithIdentifier(kMyViewControllerId) as! MyViewController 
self.presentViewController(loginVC, animated: true, completion: nil) 

그리고 그냥 로깅에이를 기각.

self.dismissViewControllerAnimated(true, completion: nil) 
관련 문제