0

可以创建选项卡 - 但是,如何将图形插入每个选项卡以及选项卡后,您如何将其称为新屏幕?

# 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
4

1 回答 1

2

请参阅https://github.com/HipByte/RubyMotionSamples上的“Beers”示例项目

您走在正确的轨道上,唯一的区别是您需要列出特定的视图控制器类而不是通用的 UIViewController 类。从样本中:

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

然后在这些控制器的每一个init方法中,你设置它tabBarItem来给它一个标题和图像:

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

或者,如果您还没有特定的视图控制器,我想您可以执行以下操作:

tabbar.viewControllers = [
  UIViewController.alloc.init,
  UIViewController.alloc.init
]
tabbar.viewControllers[0].tabBarItem = UITabBarItem.alloc.initWithTitle('List', image:UIImage.imageNamed('list.png'), tag:1)
# etc.
于 2012-06-14T16:51:47.550 回答