读书人

透过NSNotificationCenter更改被选中的

发布时间: 2012-06-26 10:04:13 作者: rapoo

通过NSNotificationCenter更改被选中的背景色

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];}
?

读书人网 >移动开发

热点推荐