0

The tabs can be created - however, how can you insert a graphic into each tab and when the tabs are selected, how do you call it out to a new screen?

# Create a tabbar
tabbar = UITabBarController.alloc.init

# Each Tab has a view controller allocated

tabbar.viewControllers = [
    UIViewController.alloc.init,
    UIViewController.alloc.init, 
    UIViewController.alloc.init,
    UIViewController.alloc.init
]

# Selected index to 0
tabbar.selectedIndex = 0

# The root view controller also changed
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(tabbar)

# We will force to use a full screen layout.
@window.rootViewController.wantsFullScreenLayout = true
RedNax
  • 1,507
  • 1
  • 10
  • 20

1 Answers1

2

See the "Beers" sample project at https://github.com/HipByte/RubyMotionSamples

You're on the right track, the only difference is that you'll want to list your specific view controller classes instead of the generic UIViewController class. From the sample:

tabbar.viewControllers = [BeerMapController.alloc.init,
                          BeerListController.alloc.init]

Then in each of those controllers' init methods, you set the tabBarItem to give it a title and image:

class BeerListController < UITableViewController
  def init
    if super
      self.tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
    end
    self
  end
end

Alternatively, if you don't have specific view controllers yet, I imagine you could do something like this:

tabbar.viewControllers = [
  UIViewController.alloc.init,
  UIViewController.alloc.init
]
tabbar.viewControllers[0].tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
# etc.
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • Thank you Dylan! Is there a place where the functions/parameters for UITabBarItem are found? (That are in RubyMotion syntax) ? I am looking to remove the blue bar on top or put text in there. – RedNax Jun 16 '12 at 10:14