I am making a custom bar buttons for uinavigationbar, I am using following code
UIImageView *backImgView= [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"chk_back.png"]]; [backImgView setUserInteractionEnabled:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backImgView];
[backButton setTarget:self];
[backButton setAction:@selector(BackBtn)];
checkIn_NavBar.topItem.leftBarButtonItem = backButton;
The problem is it is not calling its action. What i am doing wrong?
I accomplished this using following code:
From Apple documentation:
Initializes a new item using the specified custom view.
Parameters customView A custom view representing the item. Return Value Newly initialized item with the specified properties.
Discussion: The bar button item created by this method does not call the action method of its target in response to user interactions. Instead, the bar button item expects the specified custom view to handle any user interactions and provide an appropriate response.
Solution: "Create button with your background image (set action to this button) and init bar button with this button". For example: