2014-04-16 4 views
1

기본 로그인/로그인 화면과 사용자가 로그인하면 표시되는 기본 컨트롤러가 있습니다. 또한 URL을 통해 앱을 열면 모달 컨트롤러를 보여주고 싶습니다.로그인/가입 및 주 컨트롤러 워크 플로를 정의하는 방법은 무엇입니까?

나는이를 수행하는 방법에 대해 여러 가지 패턴을 시도했으며 아래 패턴을 사용했다. 그것은 작동하지만, 나는 아래에서하는 것보다 이것을 할 수있는 더 좋은 방법이 있어야한다고 생각합니다. 아래에 문제가 응용 프로그램이 URL 여기

를 통해 열 때 모달 컨트롤러를 열지 않는 것은 내가

class WelcomeController < UIViewController 
    include AFNetworkingClient 
    def viewDidLoad 
    super 

    rmq.stylesheet = WelcomeControllerStylesheet 
    rmq(self.view).apply_style :root_view 

    display_login unless AppHelper.user_set? 

    end 
    def display_login 
    @login = LoginController.alloc.init 
    @login.delegate = self 
    self.presentViewController(@login, animated:false, completion:nil) 
    end 
.... 
end 
WelcomeController의

class AppDelegate 
    attr_reader :window 
    include AFNetworkingClient 

    def application(application, didFinishLaunchingWithOptions:launchOptions) 
    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) 
    if AppHelper.user_set? 
     initAFNetworkingClient 
     Color.fetch(AFMotion::Client) do |data| 
     main_controller = ColorController.alloc.initWithData(data) 
     @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller) 
     end 
    else 
     main_controller = WelcomeController.alloc.initWithNibName(nil, bundle: nil) 
     @window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller) 
    end 
    @window.makeKeyAndVisible 
    true 
    end 

    # This doesn't show the modal controller for some reason 
    def application(application, openURL:url, sourceApplication:sourceApp, annotation:annotation) 
    Color.fetch(AFMotion::Client) do |data| 
     main_controller = ColorController.alloc.initWithData(data) 
     ctlr = UINavigationController.alloc.initWithRootViewController(self.add_color_controller) 
     ctlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical 
     ctlr.delegate = self 
     self.presentViewController(ctlr, animated:true, completion:nil) 
    end 
    end 
    def add_color_controller 
    @add_color_controller ||= MyModalController.new.tap do |ctlr| 
     ctlr.navigationItem.leftBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
      UIBarButtonSystemItemCancel, 
      target: self, 
      action: :cancel) 

     ctlr.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(
      UIBarButtonSystemItemDone, 
      target: self, 
      action: :done) 

     ctlr.navigationItem.rightBarButtonItem.enabled = false 
    end 
    end 

    def cancel 
    self.dismissViewControllerAnimated(true, completion:nil) 
    end 
end 

부분을 수행하고있는 무슨이다

질문

  • 위에서 언급 한 워크 플로를 더 효과적으로 관리 할 수 ​​있습니까? Application windows are expected to have a root view controller at the end of application launch

답변

0

누락 된 것은 Color.fetch가 실행되는 동안 표시하는 컨트롤러입니다 : 나는 URL을 사용하여 응용 프로그램을 열 때 오류가 발생하지 않도록

  • 어떻게 위의 코드를 해결할 수 있습니다. 따라서 메서드는 반환하고 @window.rootViewController은 Color.fetch 내의 블록이 호출 될 때까지 아무 것도 설정되지 않습니다. 그렇기 때문에 presentViewController(..)에 문제가 있습니다. 제시 할 컨트롤러가 없습니다!

    그래서 첫 번째 반복에는 "로드 중"보기 컨트롤러가 있어야합니다. 그것은 위대한 사용자 경험, 아니지만 ... 그럼 난 Color.fetch의 마지막 결과를 저장하고 그 다음에 새로운 데이터가 오면 UI를 업데이 트하는 ColorController를 수정합니다. 조금 더 많은 작업이 있지만 더 나은 UX가 될 것입니다. 그리고 캐시 된 데이터가 없으면 자체 '로딩'화면을 가질 수 있습니다. 또는 LoadingViewController를 모달로 표시 할 수 있습니다.

    이것은 AppDelegate의 코드를 Color.fetch으로 옮기는 작업과 관련이 있습니다. 어쨌든 (분리)하는 것이 좋습니다. 나는 컨트롤러가 자신의 데이터를 로딩해야한다고 생각한다.