Search code examples
rubymotion

rubymotion- formotion & rendering data to appear on tableview


i have an app thats setup to use formation in one controller and i have another controller thats a uivuewcontroller with a subclass of tableview and i want the information in the form controller to appear on my tableview. i used cdq to store the data also.

heres a example of my code, not sure if if the way I'm trying to do this is correct or not.

def init
@form = Formotion::Form.new({
persist_as: :post,
sections: [{
  title: "post",
  rows: [{
    title: "name",
    key: :name,
    placeholder: "example name",
    type: :string,
    input_accessory: :done,
    }
...
{
      rows: [{
      title: "Post",
      type: :submit,
    }]
@form.on_submit do |form|
  process_info(form)
end
super.initWithForm(form)
end


def process_info(form)
  data = form.render
end

any example code or steps to make it appear on my other uiviewcontroller with the tableview subclass would be greatly appreciated.

--EDIT--

heres what i added to process info method

def process_info
data = form.render
[:name,:example,:example].each { |prop|
PostScreenController.controller.send(prop.to_s + "="  , form.render[prop])
}
self.navigationController.dismissViewControllerAnimated(true, completion:lambda{})
end

one more thing to add is that the PostScreeController is the controller with the tableview that I'm trying to populate with the formotion data.

and i got this error message in the terminal

Terminating app due to uncaught exception 'NoMethodError', reason: 'post_controller.rb:95:in `block in process_info': undefined method `controller' for PostScreenController:Class (NoMethodError)

Solution

  • Here's one that I use. Very similar. I just think you're passing some variables around that aren't quite right. Ie: Setting form to an instance variable but then passing a standard variable in to the process_info method. Hope this helps. :)

    def init
      self.initWithForm(new_form)
    end
    
    def new_form
      form = Formotion::Form.new({
        persist_as: :post,
        sections: [{
          title: "post",
          rows: [{
            title: "name",
            key: :name,
            placeholder: "example name",
            type: :string,
            input_accessory: :done,
            },
          # ....
       {
        rows: [{
         title: "Post",
         type: :submit,
        }]]
    
      form.on_submit do |f|
        process_info
      end
    
      form
    end
    
    def process_info
      data = form.render
    end