@@ -47,11 +47,24 @@ - (instancetype)init
4747{
4848 self = [super init ];
4949 if (self) {
50- [[UnReadManager shareManager ] addObserver: self forKeyPath: kUnReadKey_messages options: NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context: nil ];
51- [[UnReadManager shareManager ] addObserver: self forKeyPath: kUnReadKey_notifications options: NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context: nil ];
50+ RAC (self, rdv_tabBarItem.badgeValue ) = [RACSignal combineLatest: @[RACObserve ([UnReadManager shareManager ], messages),
51+ RACObserve ([UnReadManager shareManager ], notifications)]
52+ reduce: ^id (NSNumber *messages, NSNumber *notifications){
53+ NSString *badgeTip = @" " ;
54+ NSNumber *unreadCount = [NSNumber numberWithInteger: messages.integerValue +notifications.integerValue];
55+ if (unreadCount.integerValue > 0 ) {
56+ if (unreadCount.integerValue > 99 ) {
57+ badgeTip = @" 99+" ;
58+ }else {
59+ badgeTip = unreadCount.stringValue ;
60+ }
61+ }
62+ return badgeTip;
63+ }];
5264 }
5365 return self;
5466}
67+
5568- (id )initWithNibName : (NSString *)nibNameOrNil bundle : (NSBundle *)nibBundleOrNil
5669{
5770 self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
@@ -97,7 +110,6 @@ - (void)viewDidLoad
97110 [weakSelf refreshMore ];
98111 }];
99112
100- [self refreshBadgeTip ];
101113 [self .refreshControl beginRefreshing ];
102114 [self .myTableView setContentOffset: CGPointMake (0 , -44 )];
103115 [self refresh ];
@@ -119,13 +131,8 @@ - (void)didReceiveMemoryWarning
119131 // Dispose of any resources that can be recreated.
120132}
121133- (void )dealloc {
122-
123- [[UnReadManager shareManager ] removeObserver: self forKeyPath: kUnReadKey_messages ];
124- [[UnReadManager shareManager ] removeObserver: self forKeyPath: kUnReadKey_notifications ];
125-
126134 _myTableView.delegate = nil ;
127135 _myTableView.dataSource = nil ;
128-
129136}
130137
131138- (void )sendMsgBtnClicked : (id )sender {
@@ -223,7 +230,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
223230 if (indexPath.row < 3 ) {
224231 TipsViewController *vc = [[TipsViewController alloc ] init ];
225232 vc.myCodingTips = [CodingTips codingTipsWithType: indexPath.row];
226- vc.notificationDict = _notificationDict;
227233 [self .navigationController pushViewController: vc animated: YES ];
228234 }else {
229235 PrivateMessage *curMsg = [_myPriMsgs.list objectAtIndex: indexPath.row-3 ];
@@ -265,27 +271,4 @@ - (void)removeConversation:(PrivateMessage *)curMsg inTableView:(UITableView *)t
265271 }
266272 }];
267273}
268-
269-
270- #pragma mark KVO_UnRead
271- - (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context {
272- if ([keyPath isEqualToString: kUnReadKey_messages ] || [keyPath isEqualToString: kUnReadKey_notifications ]){
273- [self refreshBadgeTip ];
274- }
275- }
276-
277- - (void )refreshBadgeTip {
278- NSString *badgeTip = @" " ;
279- NSNumber *unreadCount = [NSNumber numberWithInteger: ([UnReadManager shareManager ].messages.integerValue +[UnReadManager shareManager ].notifications.integerValue)];
280- if (unreadCount.integerValue > 0 ) {
281- if (unreadCount.integerValue > 99 ) {
282- badgeTip = @" 99+" ;
283- }else {
284- badgeTip = unreadCount.stringValue ;
285- }
286- }
287- [self .rdv_tabBarItem setBadgeValue: badgeTip];
288- }
289-
290-
291274@end
0 commit comments