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:
Katsuyoshi Ito
2013-06-10 17:47:48 +09:00
parent 3fc4096c68
commit 4f71e2ac34

View File

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