Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I build RubyMotion apps with Interface Builder?

Tags:

Ruby Motion just came out, and the screencast doesn't seem to say anything about whether or not you can use Interface Builder to build your interfaces and integrate them in your RubyMotion project. Is such a thing possible? Or do I really have code everything by hand, not to mention maintain to different pieces of code for iPhone/iPad?

My rep isn't high enough to create a rubymotion tag, so please help out if appropriate.

like image 662
Alexander Wallace Matchneer Avatar asked May 04 '12 06:05

Alexander Wallace Matchneer


2 Answers

I'd just like to point out that RubyMotion 1.3 now support automatic compilation of .xib files that you put into the resources folder. So now the workflow becomes :

  1. Create your .xib file using XCode (no need to create a project, just use File|New...|File) and save it into the resources folder. As there is no support for outlets yet, be careful to set the tag property for each control you want to use in your code (you'll find in the property sheet of each component under the "View" header).
  2. RubyMotion will take care of compiling your .xib file into a .nib file, so enjoy :)
  3. In your UIViewController derived class, load the nib using loadNibNamed:owner:options:, as shown below.
  4. In viewDidLoad, fetch your various components using viewWithTag: and add events handlers using addTarget:action:forControlEvents:,as show below.
  5. As a bonus, next time you want to edit your xib, just do open resources/MyView.xib, it will only launch the good parts of XCode.

    class CalculatorViewController < UIViewController     def loadView         views = NSBundle.mainBundle.loadNibNamed "Keyboard", owner:self, options:nil         self.view = views[0]     end      def viewDidLoad         button = view.viewWithTag 1         button.addTarget self, action:'buttonTapped:', forControlEvents:UIControlEventTouchUpInside     end      def buttonTapped(button)         # ...     end end 
like image 74
Nicolas Lehuen Avatar answered Nov 06 '22 02:11

Nicolas Lehuen


Yes you can use Interface Builder in RubyMotion.

.xib files that are located in the resources directory are automatically compiled into .nib files and available to your project.

There is even a way to support outlets if you are so inclined :

https://github.com/yury/ib#readme
http://ianp.org/2012/05/07/rubymotion-and-interface-builder/

like image 26
dmin7b5 Avatar answered Nov 06 '22 02:11

dmin7b5