class ProMotion::TabBarController
Attributes
name[RW]
pm_tab_delegate[RW]
Public Class Methods
new(*screens)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 5 def self.new(*screens) tab_bar_controller = alloc.init screens = screens.flatten.map { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes tag_index = 0 view_controllers = screens.map do |s| s.tabBarItem.tag = tag_index s.tab_bar = WeakRef.new(tab_bar_controller) if s.respond_to?("tab_bar=") tag_index += 1 s.navigationController || s end tab_bar_controller.viewControllers = view_controllers name = "" tab_bar_controller.delegate = tab_bar_controller tab_bar_controller end
Public Instance Methods
find_tab(tab_title)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 58 def find_tab(tab_title) viewControllers.find { |vc| vc.tabBarItem.title == tab_title } end
name=(n)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 24 def name=(n) @name = n tab_bar_order = NSUserDefaults.standardUserDefaults.arrayForKey("tab_bar_order_#{@name}") if tab_bar_order sorted_controllers = [] unsorted_controllers = self.viewControllers.copy tab_bar_order.each do |order| sorted_controllers << unsorted_controllers[order] end self.viewControllers = sorted_controllers open_tab(0) # Open the tab on the far left end end
open_tab(tab)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 38 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 unless selected_tab_vc mp "Unable to open tab #{tab} -- not found.", force_color: :red return end return unless should_select_tab_try(selected_tab_vc) self.selectedViewController = selected_tab_vc on_tab_selected_try(selected_tab_vc) selected_tab_vc end
preferredInterfaceOrientationForPresentation()
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 87 def preferredInterfaceOrientationForPresentation current_view_controller_try(:preferredInterfaceOrientationForPresentation) end
shouldAutorotate()
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 79 def shouldAutorotate current_view_controller_try(:shouldAutorotate) end
supportedInterfaceOrientations()
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 83 def supportedInterfaceOrientations current_view_controller_try(:supportedInterfaceOrientations) end
tabBarController(tbc, shouldSelectViewController: vc)
click to toggle source
Cocoa touch methods below
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 63 def tabBarController(tbc, shouldSelectViewController: vc) should_select_tab_try(vc) end
Private Instance Methods
can_send_method_to_delegate?(method)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 118 def can_send_method_to_delegate?(method) pm_tab_delegate && pm_tab_delegate.respond_to?(:weakref_alive?) && pm_tab_delegate.weakref_alive? && pm_tab_delegate.respond_to?("#{method}:") end
current_view_controller()
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 108 def current_view_controller selectedViewController || viewControllers.first end
current_view_controller_try(method, *args)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 112 def current_view_controller_try(method, *args) return unless current_view_controller.respond_to?(method) current_view_controller.send(method, *args) end
on_tab_selected_try(vc)
click to toggle source
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 101 def on_tab_selected_try(vc) method_name = :on_tab_selected return unless can_send_method_to_delegate?(method_name) pm_tab_delegate.send(method_name, vc) end
should_select_tab_try(vc)
click to toggle source
Defaults to true if :should_select_tab tab is not implemented by the tab delegate.
# File lib/ProMotion/cocoatouch/tab_bar_controller.rb, line 94 def should_select_tab_try(vc) method_name = :should_select_tab return true unless can_send_method_to_delegate?(method_name) pm_tab_delegate.send(method_name, vc) end