【问题标题】:How can I avoid the error "Cannot convert 'UIButtonType' to 'UIBarButtonItemStyle' in argument passing?"如何避免错误“无法在参数传递中将 'UIButtonType' 转换为 'UIBarButtonItemStyle'?”
【发布时间】:2011-01-08 22:00:18
【问题描述】:

我正在将 zxing(二维码扫描)整合到我的 iPhone 项目中。我按照说明使其工作,其中包括将类文件从 .m 重命名为 .mm。

当我这样做时,我的项目无法编译并出现错误:“无法在参数传递中将 'UIButtonType' 转换为 'UIBarButtonItemStyle'”,这发生在我的类中的以下代码中(添加一个按钮以允许用户调用扫描操作)

// Add scan button
UIBarButtonItem *qrScanButton = [[UIBarButtonItem alloc] initWithTitle:@"Scan" 
    style: UIButtonTypeInfoLight 
    target:self action:@selector(qrScanButtonPressed)]; 
    [[self navigationItem] setLeftBarButtonItem: qrScanButton];
    [qrScanButton release];

从错误看来问题出在

风格:UIButtonTypeInfoLight

如果我注释掉整个块,那么代码编译得很好。当文件类型变为 .mm 时,它将停止工作。这是一个非常标准的代码块,用于添加备用后退按钮等。

如果有人对如何解决有任何想法,我将不胜感激。

【问题讨论】:

    标签: iphone objective-c cocoa-touch uikit uiviewcontroller


    【解决方案1】:

    问题在于“UIButtonTypeInfoLight”不是有效的UIBarButtonItemStyle。 (在上述链接底部搜索 UIBarButtonItemStyle 常量。)

    当前有效值为 (iOS 4.2):

    • UIBarButtonItemStylePlain
    • UIBarButtonItemStyleBordered
    • UIBarButtonItemStyleDone

    您正在传递 UIButtonTypeInfoLight,它是 UIButtonType,在 UIBarButtonItem 的范围内没有意义。

    【讨论】:

      猜你喜欢
      • 2020-06-20
      • 1970-01-01
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 2022-06-11
      • 2014-10-09
      • 2012-03-22
      相关资源
      最近更新 更多