我有一個基本的應用程序,登錄/註冊屏幕和主控制器,當用戶登錄後顯示。此外,當通過URL打開應用程序時,我想顯示模態控制器。如何定義登錄/註冊和主控制器工作流程?
我已經嘗試了幾種模式,如何做到這一點,並已解決下面的模式。它的工作,但是,我覺得應該有一個更好的方式來做到這一點比我下面做的。用下面的問題是,當應用程序通過URL
這裏開不開模態控制器是我在做什麼WelcomeController
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
的
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
部分
問題
- 有沒有更好的方法來管理我上面提到的工作流程?
- 如何解決上面的代碼,這樣,當我打開應用程序的URL也不會引發錯誤:
Application windows are expected to have a root view controller at the end of application launch