Xcode を使用して iOS アプリケーションを作成しましたが、これを RubyMotion に置き換えています。
Interface Builder を使用して、View Controller の 1 つのナビゲーション バーにセグメント化されたコントロールを追加することができました。RubyMotion でこれをプログラムで再作成しようとすると、エラーの内容を報告せずにアプリがクラッシュします。
誰かが私が間違っているところを指摘できますか? また、init はこれを宣言するのに最適な場所ですか? または、viewDidLoad などのビュー ライフサイクル コールバックの 1 つですか?
class MyController < UIViewController
def init
if super
image = UIImage.imageNamed('tab_bar_icons/one.png')
self.tabBarItem = UITabBarItem.alloc.initWithTitle('One', image: image, tag:1)
self.navigationItem.titleView = searchTypeContol # when commented out, the app doesn't crash!
end
self
end
def searchTypeControl
@searchTypeControl ||= begin
_searchTypeControl = UISegmentedControl.alloc.initWithFrame( CGRectZero)
_searchTypeControl.segmentedControlStyle = UISegmentedControlStyleBar
_searchTypeControl.insertSegmentWithTitle('One', atIndex: 0, animated: false)
_searchTypeControl.insertSegmentWithTitle('Two', atIndex: 0, animated: false)
_searchTypeControl.insertSegmentWithTitle('Three', atIndex: 0, animated: false)
_searchTypeControl.sizeToFit
_searchTypeControl
end
end
end