Sha256: ea1678d97f1ebee3573fc390a90ab3a348c3283f64182b10441bafd0c7a4e560

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module ProMotion
  class TabBarController < UITabBarController
    
    def self.new(*screens)
      tab_bar_controller = alloc.init

      view_controllers = []

      screens = screens.flatten.map { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes

      tag_index = 0
      screens.each do |s|
        s.tabBarItem.tag = tag_index
        s.tab_bar = tab_bar_controller if s.respond_to?("tab_bar=")
        view_controllers << (s.navigationController || s)
        tag_index += 1
      end

      tab_bar_controller.viewControllers = view_controllers
      tab_bar_controller
    end
    
    def open_tab(tab)
      if tab.is_a? String
        selected_tab_vc = find_tab(tab)
      elsif tab.is_a? Numeric
        selected_tab_vc = viewControllers[tab]
      end
      
      if selected_tab_vc
        self.selectedViewController = selected_tab_vc if selected_tab_vc
      else
        PM.logger.error "Unable to open tab #{tab.to_s} -- not found."
        nil
      end
    end
    
    def find_tab(tab_title)
      self.viewControllers.select{ |vc| vc.tabBarItem.title == tab_title }.first
    end
  
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ProMotion-1.1.2 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.1.1 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.1.0 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.1.0.rc1 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.0.4 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.0.3 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.0.2 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.0.1 lib/ProMotion/cocoatouch/tab_bar_controller.rb
ProMotion-1.0.0 lib/ProMotion/cocoatouch/tab_bar_controller.rb