Search code examples
objective-cxcode4styleswarnings

Xcode4: Implicit conversion from enumeration type 'UIBarStyle' to different enumeration type 'UIBarButtonItemStyle'


I have this code:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle: @"Secciones" 
                                                                  style: UIBarStyleDefault
                                                                 target:nil 
                                                                 action:nil];

and on the line that says style: UIBarStyleDefault I get the following warning:

Implicit conversion from enumeration type 'UIBarStyle' to different enumeration type 'UIBarButtonItemStyle'


Solution

  • You shouldn't be a using UIBarStyle, but a UIBarButtonItemStyles instead (which is, as the name suggests, meant to be used for UIBarButtonItems):

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
        initWithTitle: @"Secciones" 
        style: UIBarButtonItemStylePlain
        target:nil 
        action:nil
    ];