MFMail组合自定义button

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; 

大家好,我试图改变邮件composer php的button的风格。 上面的代码确实改变了button的外观,但是这个动作似乎已经丢失了。 任何想法如何克服这一点? 谢谢。

对此的修复相当简单。 你给这个button添加一个方法,然后定义方法中应该发生什么。 所以首先,在声明你的button之后放置这一行。

 [button addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 

这将添加一个方法,当button被点击/触摸时被调用。 然后,在代码后面,创build该button将调用的实际方法。

 -(void)aButtonClicked:(id)sendr{ //Do stuff here } 

希望这有助于:)