How to get the view of two controllers to load at the same time

33 views
Skip to first unread message

martins

unread,
Apr 28, 2013, 9:13:59 AM4/28/13
to rubym...@googlegroups.com
Hi,

I´ve followed the instuction in the Rubymotion book and created an app that has a search and a list function.
The first screen is a search form. I´d love to put my list below that form, but I don´t understand how.

If I position the elements in non overlapping places in each controller, how to I load them both at once? Would that be the correct approach?



Here´s how I´ve set things up today:

class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
 
@search_controller = SearchController.alloc.initWithNibName(nil, bundle:nil)
@venue_controller = VenueController.alloc.initWithNibName(nil, bundle:nil)
@navigation_controller = UINavigationController.alloc.initWithRootViewController( @search_controller )
 
@window.rootViewController = @navigation_controller
@window.makeKeyAndVisible
true
end
end

The search_controller can be found in this gist and the venue_controller can be found in this.



Best regards,
Martin Stabenfeldt

Austin Seraphin

unread,
Apr 29, 2013, 1:12:20 AM4/29/13
to rubym...@googlegroups.com
A view controller can only have one view, and you can access this through the view method. Remember that views have subviews, and all of these descend from UIView. So you want to make your search form and list two separate UIView objects. Then in the controller's code just use self.view.addSubview(@search_view) and self.view.addSubview(@list_view)

And then you can just assign that as the root view controller of the navigation controller. This part took me a while to get my head around. Geomotion helped. 

 - Austin

Pay no attention to that man behind the curtain! http://behindthecurtain.us



--
 
---
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Martin Stabenfeldt

unread,
May 1, 2013, 11:18:19 AM5/1/13
to rubym...@googlegroups.com
Hi,

On Mon, Apr 29, 2013 at 01:12:20AM -0400 or thereabouts, Austin Seraphin wrote:
> A view controller can only have one view, and you can access this through the view method. Remember that views have subviews, and all of these descend from UIView. So you want to make your search form and list two separate UIView objects. Then in the controller's code just use self.view.addSubview(@search_view) and self.view.addSubview(@list_view)
>
> And then you can just assign that as the root view controller of the navigation controller. This part took me a while to get my head around. Geomotion helped.

Thanks for the suggestion Austin! :)
I´m not exactly sure how to implement it. Thought it would be smart to have a FrontpageController which can load the SearchController that should be positioned on the top, and the VenueController that´s supposted to be below.
As you might have guessed, that did not work. I´d like to keep the what I have in the VenueController separated from what´s in the SearchController, if that´s possible. It would be fantastic if you could give me an example, I´m a bit lost right now. :-|


>>> class AppDelegate
>>> def application(application, didFinishLaunchingWithOptions:launchOptions)
>>> @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
>>>
>>> @frontpage_controller = FrontpageController.alloc.initWithNibName(nil, bundle:nil)
>>> @navigation_controller = UINavigationController.alloc.initWithRootViewController( @frontpage_controller )
>>>
>>> @window.rootViewController = @navigation_controller
>>> @window.makeKeyAndVisible
>>> true
>>> end
>>> end

>>> class FrontpageController < UIViewController
>>> def viewDidLoad
>>> super
>>> self.title = "Frontpage"
>>>
>>> @search_controller = SearchController.alloc.initWithNibName(nil, bundle:nil)
>>> @venue_controller = VenueController.alloc.initWithNibName(nil, bundle:nil)
>>>
>>> # This does not work:
>>> self.view.addSubview(@search_controller)
>>> self.view.addSubview(@venue_controller)
>>> end
>>> end

Colin T.A. Gray

unread,
May 2, 2013, 11:11:13 AM5/2/13
to rubym...@googlegroups.com
The tricky thing here is that to really do this properly, you should create a container controller, and add your two controllers to that one (using the viewControllers property of UIViewController).

This is no easy task, and the documentation on it is sparse. I've had mixed success :-/


@colinta
colinta.com
github.com/colinta
Reply all
Reply to author
Forward
0 new messages