开发者

How can I avoid the error "Cannot convert 'UIButtonType' to 'UIBarButtonItemStyle' in argument passing?"

开发者 https://www.devze.com 2023-02-03 18:34 出处:网络
I am incorporating zxing (q开发者_如何转开发rcode scanning) into my iPhone project. I followed the instructions to make it work, which included renaming the class file from .m to .mm.

I am incorporating zxing (q开发者_如何转开发rcode scanning) into my iPhone project. I followed the instructions to make it work, which included renaming the class file from .m to .mm.

When I do this my project fails to compile with the error: "cannot convert 'UIButtonType' to 'UIBarButtonItemStyle' in argument passing" which occurs in the following code in my class (adding a button to allow the user to invoke the scan operation)

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

It seems from the error that the issue is with

style: UIButtonTypeInfoLight

If I comment out the whole block then the code compiles fine. It stops working when the file type becomes .mm. This is a pretty standard block of code for adding alternative back buttons etc.

If anyone has any ideas how to resolve, I would really appreciate it.


The problem is that "UIButtonTypeInfoLight" is not a valid UIBarButtonItemStyle. (Search for the UIBarButtonItemStyle constants at the bottom of the above link.)

The valid values are currently (iOS 4.2):

  • UIBarButtonItemStylePlain
  • UIBarButtonItemStyleBordered
  • UIBarButtonItemStyleDone

You're passing in UIButtonTypeInfoLight, which is a UIButtonType and meaningless in the scope of a UIBarButtonItem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号