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];
}
本文介绍如何使用NSNotificationCenter来监听iOS中的UIMenu显示和隐藏事件,并在事件触发时改变UITableViewCell的选择样式。
8732

被折叠的 条评论
为什么被折叠?



