lib/ProMotion/cocoatouch/tab_bar_controller.rb in ProMotion-2.3.1 vs lib/ProMotion/cocoatouch/tab_bar_controller.rb in ProMotion-2.4.0
- old
+ new
@@ -1,10 +1,9 @@
module ProMotion
class TabBarController < UITabBarController
+ attr_accessor :pm_tab_delegate, :name
- attr_accessor :pm_tab_delegate
-
def self.new(*screens)
tab_bar_controller = alloc.init
screens = screens.flatten.map { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes
@@ -15,14 +14,29 @@
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
+ 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
+
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]
@@ -44,9 +58,17 @@
end
# Cocoa touch methods below
def tabBarController(tbc, didSelectViewController: vc)
on_tab_selected_try(vc)
+ end
+
+ def tabBarController(tbc, didEndCustomizingViewControllers:vcs, changed:changed)
+ if changed
+ tab_order = vcs.map{ |vc| vc.tabBarItem.tag }
+ NSUserDefaults.standardUserDefaults.setObject(tab_order, forKey:"tab_bar_order_#{@name}")
+ NSUserDefaults.standardUserDefaults.synchronize
+ end
end
def shouldAutorotate
current_view_controller_try(:shouldAutorotate)
end