mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-06-15 10:37:57 +08:00
add callback after created controller.
Sometimes view controller has a data.
The controller was set as a root view controller to the window before called "before" block.
But a data is not set at this point.
The view controller access to nil, and crash sometime even if I set a data in "before" block.
After created controller it will call the specified callback method if you set :after_created option
# Example
describe MyViewController do
tests MyViewController, after_created: :after_created_controller
def after_created_controller controller
# you can set data to the controller here
controller.my_data = "foo"
end
.
.
end
This commit is contained in:
@@ -213,10 +213,15 @@ module Bacon
|
||||
attr_accessor :controller
|
||||
|
||||
def controller
|
||||
@controller ||= if @options[:id]
|
||||
storyboard.instantiateViewControllerWithIdentifier(@options[:id])
|
||||
else
|
||||
@controller_class.alloc.init
|
||||
@controller ||= begin
|
||||
c = nil
|
||||
if @options[:id]
|
||||
c = storyboard.instantiateViewControllerWithIdentifier(@options[:id])
|
||||
else
|
||||
c = @controller_class.alloc.init
|
||||
end
|
||||
send(@options[:after_created], c) if @options[:after_created]
|
||||
c
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user