module Teacup::ControllerClass
Attributes
layout_definition[R]
Public Instance Methods
layout(stylename=nil, properties={})
click to toggle source
Define the layout of a controller's view.
This function is analogous to Teacup::Layout#layout
, though it is designed so you can create an entire layout in a declarative manner in your controller.
The hope is that this declarativeness will allow us to automatically deal with common iOS programming tasks (like releasing views when low-memory conditions occur) for you. This is still not implemented though.
@param name The stylename for your controller's view.
@param properties Any extra styles that you want to apply.
@param &block The block in which you should define your layout.
It will be instance_exec'd in the context of a controller instance.
@example
class MyViewController < UIViewController def teacup_layout root :my_view subview UILabel, title: "Test" subview UITextField, { frame: [[200, 200], [100, 100]] delegate: self } subview(UIView, :shiny_thing) { subview UIView, :centre_of_shiny_thing } end end
# File lib/teacup/teacup_controller.rb, line 43 def layout(stylename=nil, properties={}) if block_given? msg = <<-MSG Time to update your syntax! It was discovered that passing a block to the Controller##layout was causing irreparable memory leaks. The only recourse is to use a new syntax and remove the old functionality. If you need to assign a stylename to the root view, you can still do this using `layout :stylename`, but you cannot pass a block to this class method any longer. Instead, define a method called `teacup_layout` and create your views there. No other changes are required. MSG raise msg end @layout_definition = [stylename, properties] end