Pete
Pete

Reputation: 23

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

I am incorporating zxing (qrcode 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.

Upvotes: 0

Views: 281

Answers (1)

John Parker
John Parker

Reputation: 54445

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.

Upvotes: 3

Related Questions