
There is a bar button item in my xib file.
.h:
@property (nonatomic, retain) IBOutlet UIBarButtonItem *toolbarButton;
.m:
UIButton *aboutToolbarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aboutToolbarButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[aboutToolbarButton setTitle:@"about" forState:UIControlStateNormal];
aboutToolbarButton.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
[aboutToolbarButton.layer setCornerRadius:4.0f];
[aboutToolbarButton.layer setMasksToBounds:YES];
[aboutToolbarButton.layer setBorderWidth:1.0f];
[aboutToolbarButton.layer setBorderColor: [[UIColor grayColor] CGColor]];
aboutToolbarButton.frame = CGRectMake(0.0, 100.0, 60.0, 30.0);
[aboutToolbarButton addTarget:self action:@selector(getToUserSettingsViewController) forControlEvents:UIControlEventTouchUpInside];
self.toolbarButton = [[UIBarButtonItem alloc] initWithCustomView:aboutToolbarButton];
and I connect with the button to file’s owner,but it doesn’t work, please help me with this.
Thank you very much!
This is what is happening:
Using interface builder, you link the UIBarButtonItem to the controller, telling the controller that that particular UIBarButtonItem is the self.toolbarButton.
Then in your code, you tell your controller that the self.toolbarButton is now another button that you created by code(but you haven’t added to your view yet) using the
Now the self.toolbarButton is no more the button in the interface builder.
Thus, the button you see in your view is in your opinion ‘not working’ because you haven’t assigned any selector to that button.
I would recommend you to link the IBAction to the button using interface builder.
Having said all this, it seems that you don’t understand how interface builder works. I suggest you read more tutorials or even better, get this book by Apress:
http://www.apress.com/9781430236054