Skip to content

Commit 0c370aa

Browse files
author
panshiyu
committed
加入search btn的红点判断和存储
1 parent 672347b commit 0c370aa

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

Coding_iOS/Controllers/RootControllers/Tweet_RootViewController.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ - (void)viewDidLoad
9494
// [self refreshFirst];
9595
// }];
9696

97-
CSBarButtonItem *leftBarItem =[[CSBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search_Nav"] style:UIBarButtonItemStylePlain target:self action:@selector(searchItemClicked:)];
98-
leftBarItem.showBadge = YES;
97+
BOOL isBadgeValid = ![CSSearchModel hasSearchBadgeShown];
98+
UIBarButtonItem *leftBarItem =[UIBarButtonItem itemWithIcon:@"search_Nav" showBadge:isBadgeValid target:self action:@selector(searchItemClicked:)];
9999
[self.navigationItem setLeftBarButtonItem:leftBarItem animated:NO];
100100

101101
_tweetsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
@@ -251,6 +251,14 @@ - (void)deleteComment:(Comment *)comment ofTweet:(Tweet *)tweet{
251251
- (void)searchItemClicked:(id)sender{
252252
CSSearchVC *searchVC = [[CSSearchVC alloc] init];
253253
[self.navigationController pushViewController:searchVC animated:YES];
254+
255+
BOOL isBadgeValid = ![CSSearchModel hasSearchBadgeShown];
256+
if (isBadgeValid) {
257+
//存一下
258+
[CSSearchModel invalidSearchBadge];
259+
UIBarButtonItem *leftBarItem =[UIBarButtonItem itemWithIcon:@"search_Nav" showBadge:NO target:self action:@selector(searchItemClicked:)];
260+
[self.navigationItem setLeftBarButtonItem:leftBarItem animated:NO];
261+
}
254262
}
255263

256264
#pragma mark Refresh M

Coding_iOS/Controllers/Search/CSSearchVC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import "CSSearchModel.h"
1011

1112
@interface CSSearchVC : UIViewController
1213

Coding_iOS/Util/OC_Category/UIBarButtonItem+Common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010

1111
@interface UIBarButtonItem (Common)
1212
+ (UIBarButtonItem *)itemWithBtnTitle:(NSString *)title target:(id)obj action:(SEL)selector;
13+
14+
+ (UIBarButtonItem *)itemWithIcon:(NSString*)iconName showBadge:(BOOL)showbadge target:(id)obj action:(SEL)selector;
1315
@end
16+

Coding_iOS/Util/OC_Category/UIBarButtonItem+Common.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@ + (UIBarButtonItem *)itemWithBtnTitle:(NSString *)title target:(id)obj action:(S
1515
return buttonItem;
1616
}
1717

18+
+ (UIBarButtonItem *)itemWithIcon:(NSString*)iconName showBadge:(BOOL)showbadge target:(id)obj action:(SEL)selector {
19+
UIButton* button = [[UIButton alloc] init];
20+
button.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 0);
21+
[button setImage:[UIImage imageNamed:iconName] forState:UIControlStateNormal];
22+
[button setImage:[UIImage imageNamed:iconName] forState:UIControlStateHighlighted];
23+
CGSize imgSize = button.imageView.image.size;
24+
button.size = CGSizeMake(imgSize.width, imgSize.height + 20);
25+
CGFloat pointX = button.frame.size.width - 25;
26+
[button addBadgeTip:@"" withCenterPosition:CGPointMake(pointX, 25)];
27+
return [[UIBarButtonItem alloc] initWithCustomView:button];;
28+
}
29+
1830
@end

0 commit comments

Comments
 (0)