Can I build RubyMotion apps with Interface Builder?
interface-builder, ios, rubymotion
Solution
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 :
- 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).
- RubyMotion will take care of compiling your `.xib` file into a `.nib` file, so enjoy :)
- In your `UIViewController` derived class, load the nib using `loadNibNamed:owner:options:`, as shown below.
- In `viewDidLoad`, fetch your various components using `viewWithTag:` and add events handlers using `addTarget:action:forControlEvents:`,as show below.
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
Problem
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.