Module: Teacup::ControllerClass

Defined in:
lib/teacup/teacup_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#layout_definitionObject (readonly)

Returns the value of attribute layout_definition.



7
8
9
# File 'lib/teacup/teacup_controller.rb', line 7

def layout_definition
  @layout_definition
end

Instance Method Details

#layout(stylename = nil, properties = {}, &block) ⇒ Object

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.

Examples:

class MyViewController < UIViewController
  layout :my_view do
    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

Parameters:

  • name

    The stylename for your controller’s view.

  • properties (defaults to: {})

    Any extra styles that you want to apply.

  • &block

    The block in which you should define your layout. It will be instance_exec’d in the context of a controller instance.



42
43
44
# File 'lib/teacup/teacup_controller.rb', line 42

def layout(stylename=nil, properties={}, &block)
  @layout_definition = [stylename, properties, block]
end