1,通过NSNotificationCenter注册监听事件
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuWillShow:) name:UIMenuControllerWillShowMenuNotification object:nil];
2,当UIMenu 显示的时候调用以下方法
- (void) menuWillShow:(NSNotification *)notification
{
self.selectionStyle = UITableViewCellSelectionStyleBlue;
if ((self.delegate != nil) && [self.delegate respondsToSelector:@selector(emailableCell:selectCellAtIndexPath:)]) {
[self.delegate emailableCell:self selectCellAtIndexPath:self.indexPath];
}
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIMenuControllerWillShowMenuNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(menuWillHide:)
name:UIMenuControllerWillHideMenuNotification
object:nil];
}
3,当UIMenu 消失的时候调用以下方法
- (void) menuWillHide:(NSNotification *)notification { if ((self.delegate != nil) && [self.delegate respondsToSelector:@selector(emailableCell:deselectCellAtIndexPath:)]) { [self.delegate emailableCell:self deselectCellAtIndexPath:self.indexPath]; } self.selectionStyle = UITableViewCellSelectionStyleNone; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIMenuControllerWillHideMenuNotification object:nil]; }