2012-06-21 33 views
0

我已經使用Xcode構建了一個iOS應用程序,我現在將其轉換爲RubyMotion。如何使用RubyMotion將UISegmentedControl插入到導航欄?

使用界面生成器我能夠在我的一個視圖控制器上的導航欄中添加一個分段控件。當我嘗試在RubyMotion中以編程方式重新創建時,應用程序崩潰而不報告錯誤是什麼。

任何人都可以指出我要去哪裏錯了嗎? 另外,init是否是聲明這個最好的地方?或者其中一個視圖生命週期回調,如viewDidLoad?

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  

回答

0

這是一個錯字...:/

線#7應該是searchTypeControlsearchTypeContol

我希望RubyMotion曾報道這回我:(