Reputation: 1507
I have two controllers - how can I call the functions in them from the console?
(main)>
Upvotes: 2
Views: 1146
Reputation: 3659
Most of the time there is a hierarchy of UIViewController
-s, and you can tap into those. starting at the UIWindow#rootViewController
instance, and navigating through the childViewControllers
. I would recommend either using BubbleWrap
to access the window (App.window
) or delegate (App.delegate
). The SugarCube
gem, which I maintain, provides an easy way to view the view or viewController hierarchies, too - the tree
and tree root
commands are available in the REPL for just this purpose.
Upvotes: 0
Reputation: 3670
I usually add a temporary global variable in the view controller to make it easier to access it from the console.
def viewDidLoad
$temp_view = self
end
It is not pretty, but gets the job done.
Upvotes: 5
Reputation: 2457
The only way I can figure out how to do this is by using the UIApplication sharedApplication class method and drilling down from there, which is pretty icky.
(main)> UIApplication.sharedApplication.delegate
=> #<AppDelegate:0x6c8a800 @window=#<UIWindow:0x6e71280>>
Unfortunately to access the window I had to add an attr_reader :window
to my AppDelegate class to access this private variable and then drill down even further to get at the view controllers:
(main)> vc = UIApplication.sharedApplication.delegate.window.rootViewController
=> #<TouchesViewController:0x8c747c0>
Now you should be able to call any public methods on that view controller.
Upvotes: 7