lib/ProMotion/screens/_screen_module.rb in ProMotion-0.6.0 vs lib/ProMotion/screens/_screen_module.rb in ProMotion-0.6.1
- old
+ new
@@ -4,17 +4,20 @@
include ProMotion::ScreenElements
include ProMotion::SystemHelper
include ProMotion::ScreenTabs
include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2")
- attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal, :split_screen
+ attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal, :split_screen, :title
def on_create(args = {})
unless self.is_a?(UIViewController)
raise StandardError.new("ERROR: Screens must extend UIViewController or a subclass of UIViewController.")
end
+
+ self.title = self.class.send(:get_title)
+
args.each do |k, v|
self.send("#{k}=", v) if self.respond_to?("#{k}=")
end
self.add_nav_bar if args[:nav_bar]
@@ -68,17 +71,28 @@
def set_nav_bar_left_button(title, args={})
args[:title] = title
set_nav_bar_button :left, args
end
-
+
+ # If you call set_nav_bar_button with a nil title and system_icon: UIBarButtonSystemItemAdd (or any other
+ # system icon), the button is initialized with a barButtonSystemItem instead of a title.
def set_nav_bar_button(side, args={})
args[:style] ||= UIBarButtonItemStyleBordered
args[:target] ||= self
args[:action] ||= nil
- button = UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action])
+ button = case args[:title]
+ when String
+ UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action])
+ when UIImage
+ UIBarButtonItem.alloc.initWithImage(args[:title], style: args[:style], target: args[:target], action: args[:action])
+ when Symbol, NilClass
+ UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], target: args[:target], action: args[:action]) if args[:system_icon]
+ else
+ PM.logger.error("Please supply a title string, a UIImage or :system.")
+ end
self.navigationItem.leftBarButtonItem = button if side == :left
self.navigationItem.rightBarButtonItem = button if side == :right
button
@@ -121,18 +135,9 @@
def view_did_disappear(animated)
self.on_disappear
end
def on_disappear; end
-
- def title
- self.class.send(:get_title)
- end
-
- def title=(new_title)
- self.class.title = new_title
- super
- end
def main_controller
self.navigation_controller || self
end