问题
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel.png"]]];
button.target = picker.navigationBar.topItem.leftBarButtonItem ;
button.action = picker.navigationBar.topItem.leftBarButtonItem.action;
picker.navigationBar.topItem.leftBarButtonItem=button;
Hi folks, I'm trying to change the style of the buttons of the mail composer. The above code does change the look of the button, however the action seems to be lost. Any ideas how I can overcome this? Thanks.
回答1:
The fix for this is fairly simple. You add a method to this button and then define what should happen in the method. So first, put this line after you declare your button.
[button addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
That will add a method to be called when the button is clicked/touched. Then, later in the code, you create the actual method that the button will be calling.
-(void)aButtonClicked:(id)sendr{
//Do stuff here
}
Hope this helped :)
来源:https://stackoverflow.com/questions/8714802/mfmailcompose-custom-buttons