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 に答える