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 = {}) ⇒ 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
  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

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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