【问题标题】:How can I insert a UISegmentedControl to a navigationBar using RubyMotion?如何使用 RubyMotion 将 UISegmentedControl 插入到导航栏?
【发布时间】:2012-06-22 04:57:52
【问题描述】:

我已经使用 Xcode 构建了一个 iOS 应用程序,现在我将其转换为 RubyMotion。

使用界面生成器,我能够在我的一个视图控制器上的导航栏中添加分段控件。当我尝试在 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    

【问题讨论】:

    标签: objective-c ios uisegmentedcontrol rubymotion


    【解决方案1】:

    这是一个错字...:/

    第 7 行应该是 searchTypeControl 而不是 searchTypeContol

    我希望 RubyMotion 向我报告了这件事:(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-19
      • 2020-12-06
      • 1970-01-01
      • 2021-08-07
      • 2014-09-02
      • 1970-01-01
      相关资源
      最近更新 更多