Skip to content

Commit 6707c40

Browse files
committed
个人标签
1 parent bc9911e commit 6707c40

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

Coding_iOS/Controllers/MeSetting/SettingTagsViewController.m

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "TagsManager.h"
1616
@interface SettingTagsViewController ()
1717
@property (strong, nonatomic) UICollectionView *tagsView;
18+
@property (strong, nonatomic) NSMutableArray *mySelectedTags;
1819

1920
@end
2021

@@ -30,7 +31,7 @@ + (instancetype)settingTagsVCWithAllTags:(NSArray *)allTags selectedTags:(NSArra
3031
if (selectedTags && selectedTags.count > 0) {
3132
vc.selectedTags = [NSMutableArray arrayWithArray:selectedTags];
3233
}else{
33-
vc.selectedTags = [[NSMutableArray alloc] init];
34+
vc.selectedTags = [NSMutableArray array];
3435
}
3536
vc.doneBlock = block;
3637
return vc;
@@ -50,7 +51,18 @@ - (void)loadView{
5051
[super loadView];
5152
CGRect frame = [UIView frameWithOutNav];
5253
self.view = [[UIView alloc] initWithFrame:frame];
53-
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnClicked:)];
54+
55+
_mySelectedTags = [_selectedTags mutableCopy];
56+
57+
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(doneBtnClicked:)] animated:YES];
58+
59+
@weakify(self);
60+
RAC(self.navigationItem.rightBarButtonItem, enabled) =
61+
[RACSignal combineLatest:@[RACObserve(self, mySelectedTags)] reduce:^id (NSString *mdStr){
62+
@strongify(self);
63+
return @(![self tagsHasChanged]);
64+
}];
65+
5466
self.title = @"个性标签";
5567
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
5668
self.tagsView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
@@ -61,10 +73,17 @@ - (void)loadView{
6173
[self.view addSubview:self.tagsView];
6274
}
6375

76+
- (BOOL)tagsHasChanged{
77+
BOOL tagsHasChanged = NO;
78+
NSSet *oldSet = [NSSet setWithArray:_selectedTags], *newSet = [NSSet setWithArray:_mySelectedTags];
79+
tagsHasChanged = [newSet isEqualToSet:oldSet];
80+
return tagsHasChanged;
81+
}
82+
6483
- (void)doneBtnClicked:(id)sender{
6584
[self.navigationController popViewControllerAnimated:YES];
6685
if (self.doneBlock) {
67-
self.doneBlock(_selectedTags);
86+
self.doneBlock(_mySelectedTags);
6887
}
6988
}
7089

@@ -78,7 +97,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
7897
TagCCell *ccell = [collectionView dequeueReusableCellWithReuseIdentifier:kCCellIdentifier_Tag forIndexPath:indexPath];
7998
Tag *curTag = [_allTags objectAtIndex:indexPath.row];
8099
ccell.curTag = curTag;
81-
ccell.hasBeenSelected = [_selectedTags containsObject:curTag.id.stringValue];
100+
ccell.hasBeenSelected = [_mySelectedTags containsObject:curTag.id.stringValue];
82101
return ccell;
83102
}
84103

@@ -99,10 +118,12 @@ - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectio
99118
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
100119
Tag *curTag = [_allTags objectAtIndex:indexPath.row];
101120
NSString *tagId = curTag.id.stringValue;
102-
if ([_selectedTags containsObject:tagId]) {
103-
[_selectedTags removeObject:tagId];
121+
122+
NSMutableArray *tempArray = [self mutableArrayValueForKey:@"mySelectedTags"];
123+
if ([tempArray containsObject:tagId]) {
124+
[tempArray removeObject:tagId];
104125
}else{
105-
[_selectedTags addObject:tagId];
126+
[tempArray addObject:tagId];
106127
}
107128
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
108129
}

Coding_iOS/Controllers/TaskDescriptionViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ - (void)loadView{
5858
_markdown = _markdown? _markdown : @"";
5959
self.curIndex = (_markdown.length > 0)? 1: 0;
6060

61-
self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithBtnTitle:@"保存" target:self action:@selector(saveBtnClicked)];
61+
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:@"保存" target:self action:@selector(saveBtnClicked)] animated:YES];
6262
self.navigationItem.rightBarButtonItem.enabled = NO;
6363
}
6464

0 commit comments

Comments
 (0)