Ive put in a custom “Back” UIBarButtonItem, which is from an Image i made in photoshop. Ive managed to make it appear just fine, my problem is making it work.
My button does nothing, im assuming because i havent assigned any actions to it. I just dont know the correct syntax to do so?
Heres my code
UIImage *buttonImage = [UIImage imageNamed:@"BackButton.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
// Im assuming this is where i need to put the action...
//[backButton addTarget:self action:@selector(.......) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:backButton];
Basically, i want my new custom backbutton to function just like the default one in a regular UITableView
regards,
Andyy
You can do this in IB or you can do it in code with a call to
addTarget:action:forControlEvents:forUIControlEventTouchUpInsideto invoke a method (action) when the button is tapped. For example:This is documented in UIControl class reference, UIButton is a subclass of UIControl.
You’ll need a method which will be called when the event occurs, which I called
backButtonPressed:in my code above. This method takes one parameter, the object sending the event, something like this: