Close a modal view

115 views
Skip to first unread message

Greg Moreno

unread,
Oct 31, 2012, 10:08:17 PM10/31/12
to rubym...@googlegroups.com
Hi,

RubyMotion and iOS newbie here.

I'm currently using storyboard and so far I have manage to incorporate it with rubymotion. However, I got stuck in a modal view. I have a list of contacts, and when the  'add' button is clicked, it displays "Add contact" view with a 'Cancel' and 'Done' button. 

In the 'Add contact' view, how can I attach a handler to the 'cancel' and 'done' buttons? I assume there's a way to get a reference to the buttons so I could do something like this:

def viewDidLoad
  @cancel = get_reference('CancelButton')
  @cancel.addTarget(...)
end

Is there such a method to refer to the button? Is this the right way to do it?

Thank you.

Greg

Anush Saidmuradov

unread,
Nov 2, 2012, 3:02:19 PM11/2/12
to rubym...@googlegroups.com
Hey Greg,

If you want to incorporate a storyboard instead of generating views from code,

You can add "tags" on each subview via xcode (which would be an integer), then do this inside your view controller (I can't for the life of me find the blog where I got this from):

# for sake of example, say your button has a tag of 1

TAG_LOGIN_BUTTON = 1
button = retrieve_subview_with_tag(self, TAG_BUTTON)
button.when(UIControlEventTouchUpInside) do
    #do things here
end

Although, where I work we would like to implement all our views programmatically.

We will bring you up to speed when you start next monday ;)

Anush

Anush Saidmuradov

unread,
Nov 2, 2012, 3:11:06 PM11/2/12
to rubym...@googlegroups.com

Greg Moreno

unread,
Nov 3, 2012, 1:08:57 PM11/3/12
to rubym...@googlegroups.com
Thanks Anush.

I ended up with  a segue:

def prepareForSegue(segue, sender:sender)
    dvc = segue.destinationViewController

    case segue.identifier
    when "CancelAddContact"
      cancelAddContact(dvc)
    when "DoneAddContact"
      doneAddContact(dvc)
    else
      raise "Unhandle segue id #{segue.identifier}"
    end

end


Regards,

Greg



Reply all
Reply to author
Forward
0 new messages