lib/ProMotion/cocoatouch/tab_bar_controller.rb in ProMotion-2.2.2 vs lib/ProMotion/cocoatouch/tab_bar_controller.rb in ProMotion-2.3.0
- old
+ new
@@ -1,8 +1,10 @@
module ProMotion
class TabBarController < UITabBarController
+ 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
@@ -13,10 +15,11 @@
tag_index += 1
s.navigationController || s
end
tab_bar_controller.viewControllers = view_controllers
+ tab_bar_controller.delegate = tab_bar_controller
tab_bar_controller
end
def open_tab(tab)
if tab.is_a? String
@@ -25,10 +28,13 @@
selected_tab_vc = viewControllers[tab]
end
if selected_tab_vc
self.selectedViewController = selected_tab_vc
+ on_tab_selected_try(selected_tab_vc)
+
+ selected_tab_vc
else
PM.logger.error "Unable to open tab #{tab.to_s} -- not found."
nil
end
end
@@ -36,10 +42,13 @@
def find_tab(tab_title)
viewControllers.find { |vc| vc.tabBarItem.title == tab_title }
end
# Cocoa touch methods below
+ def tabBarController(tbc, didSelectViewController: vc)
+ on_tab_selected_try(vc)
+ end
def shouldAutorotate
current_view_controller_try(:shouldAutorotate)
end
@@ -50,9 +59,15 @@
def preferredInterfaceOrientationForPresentation
current_view_controller_try(:preferredInterfaceOrientationForPresentation)
end
private
+
+ def on_tab_selected_try(vc)
+ if pm_tab_delegate && pm_tab_delegate.respond_to?(:weakref_alive?) && pm_tab_delegate.weakref_alive? && pm_tab_delegate.respond_to?("on_tab_selected:")
+ pm_tab_delegate.send(:on_tab_selected, vc)
+ end
+ end
def current_view_controller
selectedViewController || viewControllers.first
end