kas-kad / aktagsinputview Goto Github PK
View Code? Open in Web Editor NEWconvenient input view for tags strings
License: Apache License 2.0
convenient input view for tags strings
License: Apache License 2.0
- (void)setTagsInputView:(AKTagsInputView *)tagsInputView
{
_tagsInputView = tagsInputView;
_tagsInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_tagsInputView.lookupTags = @[@"ios", @"iphone", @"objective-c", @"development", @"cocoa", @"xcode", @"icloud"];
_tagsInputView.selectedTags = [NSMutableArray array];// this will cause the bug
_tagsInputView.enableTagsLookup = YES;
}
I am initializing my AKTagsInputView as
// cats is a NSArray containing lookup tags
aktv = [[AKTagsInputView alloc] initWithFrame:frame];
aktv.allowDeleteTags = YES;
aktv.enableTagsLookup = YES;
aktv.lookupTags = cats;
[self.view addSubview:aktv];
The above code works fine. But after sometime I get new tags and I am calling
aktv.lookupTags = newCats;
Now I expect the newCats to be shown as lookup tags. But that does not work. The only way I can make it to work is
[aktv removeFromSuperView];
aktv = [[AKTagsInputView alloc] initWithFrame:frame];
aktv.allowDeleteTags = YES;
aktv.enableTagsLookup = YES;
aktv.lookupTags = newTags;
[self.view addSubview:aktv];
how to reproduce:
_tagsInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_tagsInputView.lookupTags = @[@"ios", @"iphone", @"objective-c", @"development", @"cocoa", @"xcode", @"icloud"];
_tagsInputView.selectedTags = [NSMutableArray array];
_tagsInputView.enableTagsLookup = YES;
Please add the posibility to customize the colors of the tags and other elements, because it is an awesome library and works pretty well, but we are not able to customize it.
Thanks!
You can observe significant performance issues while running the example with thousands of possible tags. For those who like algorithms and data structures optimizations tasks, there is an opportunity to improve a lookup performance using the trie (https://en.wikipedia.org/wiki/Trie).
just got zip, extracted and run, but the lookup didn't show up (while entering "obj")
if there is 9288 or more items in lookup table it becomes very slow. Better approach is using NSFetchedResultsController as a DataSource for collectionView.
@interface AKViewController ()
{
AKTagsInputView *_tagsInputView;
UITapGestureRecognizer *_tapGesture;
}
@end
and implementation
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = WK_COLOR(200, 200, 200, 1);
[self.view addSubview:[self createLabel]];
[self.view addSubview:[self createTagsInputView]];
[self.view addSubview:[self createButton]];
[self.view addSubview:[self clearButton]];
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];
[self.view addGestureRecognizer:_tapGesture];
[_tapGesture setNumberOfTapsRequired:1];
}
- (IBAction)tapAction:(id)sender
{
[self.tagsInputView resignFirstResponder];
}
BUG: I can not delete selected tags any more
Storyboard support needed
Possibly add a clear function to reset the view
Attempting to add tags in example results in an NSInternalInconsistencyException:
AKTagsInputViewExample[54660:22954455] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (6) must be equal to the number of items contained in that section before the update (7), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x000000010516c3f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104e05bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010516c25a +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000104a2328f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000103cfdfb7 -[UICollectionView _endItemAnimations] + 12835
5 UIKit 0x0000000103d031f9 -[UICollectionView performBatchUpdates:completion:] + 390
6 AKTagsInputViewExample 0x00000001033d15c4 -[AKTagsLookup filterLookupWithPredicate:] + 260
7 AKTagsInputViewExample 0x00000001033cc489 -[AKTagsInputView addNewItemWithString:completion:] + 233
8 AKTagsInputViewExample 0x00000001033cbab7 -[AKTagsInputView tagsLookup:didSelectTag:] + 103
9 AKTagsInputViewExample 0x00000001033d18ec -[AKTagsLookup tagsListView:didSelectTag:atIndexPath:] + 236
10 AKTagsInputViewExample 0x00000001033c9180 -[AKTagsListView collectionView:didSelectItemAtIndexPath:] + 320
11 UIKit 0x0000000103d04929 -[UICollectionView
- (IBAction)tapAction:(id)sender
{
[self.tagsInputView resignFirstResponder];
}
It seems to be working ok if you just tapped [+ ADD] textField and stops working if it disappears.
Logs:
AKTagsInputViewExample[49510:1619253] *** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UICollectionView.m:3917
AKTagsInputViewExample[49510:1619253] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (0) must be equal to the number of items contained in that section before the update (7), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x01c67946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x018f0a97 objc_exception_throw + 44
2 CoreFoundation 0x01c677da +[NSException raise:format:arguments:] + 138
3 Foundation 0x01564810 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118
4 UIKit 0x009f5638 -[UICollectionView _endItemAnimations] + 14381
5 UIKit 0x009fb5c8 -[UICollectionView _endUpdates] + 44
6 UIKit 0x009fb77a -[UICollectionView performBatchUpdates:completion:] + 429
7 AKTagsInputViewExample 0x00012a24 -[AKTagsLookup filterLookupWithPredicate:] + 276
8 AKTagsInputViewExample 0x0000d0c5 -[AKTagsInputView textField:shouldChangeCharactersInRange:replacementString:] + 1301
9 UIKit 0x00b195bf -[UITextField keyboardInput:shouldInsertText:isMarkedText:] + 273
10 UIKit 0x00504489 -[UIKeyboardImpl callShouldInsertText:] + 269
11 UIKit 0x0050f818 -[UIKeyboardImpl addInputEvent:executionContext:] + 1010
12 UIKit 0x0050f37c __60-[UIKeyboardImpl addInputString:withFlags:executionContext:]_block_invoke + 53
13 UIKit 0x00b41b08 -[UIKeyboardTaskExecutionContext returnExecutionToParentWithInfo:] + 289
14 UIKit 0x00b419e2 -[UIKeyboardTaskExecutionContext returnExecutionToParent] + 41
15 UIKit 0x0051421b -[UIKeyboardImpl acceptCurrentCandidateIfSelectedWithExecutionContext:] + 250
16 UIKit 0x0050f33f -[UIKeyboardImpl addInputString:withFlags:executionContext:] + 537
17 UIKit 0x0050e184 -[UIKeyboardImpl handleStringInput:withFlags:executionContext:] + 251
18 UIKit 0x0051f2c2 -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 652
19 UIKit 0x0051e7cb -[UIKeyboardImpl handleKeyEvent:executionContext:] + 181
20 UIKit 0x0051e67f __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 51
21 UIKit 0x0051e484 -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 243
22 UIKit 0x006e84f2 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 4415
23 UIKit 0x006e689d -[UIKeyboardLayoutStar touchUp:executionContext:] + 174
24 UIKit 0x0052d4c5 __28-[UIKeyboardLayout touchUp:]_block_invoke + 283
25 UIKit 0x00b420a2 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 404
26 UIKit 0x00b4275f -[UIKeyboardTaskQueue addTask:] + 144
27 UIKit 0x0052d3a2 -[UIKeyboardLayout touchUp:] + 294
28 UIKit 0x0052e0ae -[UIKeyboardLayout touchesEnded:withEvent:] + 539
29 UIKit 0x0031960a -[UIWindow _sendTouchesForEvent:] + 874
30 UIKit 0x0031a0e5 -[UIWindow sendEvent:] + 791
31 UIKit 0x002df549 -[UIApplication sendEvent:] + 242
32 UIKit 0x002ef37e _UIApplicationHandleEventFromQueueEvent + 20690
33 UIKit 0x002c3b19 _UIApplicationHandleEventQueue + 2206
34 CoreFoundation 0x01b8b1df CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
35 CoreFoundation 0x01b80ced __CFRunLoopDoSources0 + 253
36 CoreFoundation 0x01b80248 __CFRunLoopRun + 952
37 CoreFoundation 0x01b7fbcb CFRunLoopRunSpecific + 443
38 CoreFoundation 0x01b7f9fb CFRunLoopRunInMode + 123
39 GraphicsServices 0x040bc24f GSEventRunModal + 192
40 GraphicsServices 0x040bc08c GSEventRun + 104
41 UIKit 0x002c78b6 UIApplicationMain + 1526
42 AKTagsInputViewExample 0x00011e0d main + 141
43 libdyld.dylib 0x0223bac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Convenient way to remove last added tag
The solution is it just needs the cursor to be moved left by the width of the deleted tag each time a tag is deleted.
Rob
The case described here #18
AKTagCell.m
_deleteButton.enabled = selected;
from -(void)setSelected:(BOOL)selected
_deleteButton.enabled = NO;
on _deleteButton.enabled = YES;
from -(UIButton *)deleteButton
AKTagsInputView.m
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIAlertView *alertViewChangeTag = [[UIAlertView alloc] init];
[alertViewChangeTag setDelegate:self];
[alertViewChangeTag setTitle:@"Edit tag"];
[alertViewChangeTag addButtonWithTitle:@"Cancel"];
[alertViewChangeTag addButtonWithTitle:@"OK"];
[alertViewChangeTag setAlertViewStyle:UIAlertViewStylePlainTextInput];
AKTagCell* cell = (AKTagCell*)[collectionView cellForItemAtIndexPath:indexPath];
[[alertViewChangeTag textFieldAtIndex:0] setText:cell.tagName];
[[alertViewChangeTag textFieldAtIndex:0] setDelegate:self];
[alertViewChangeTag show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *newTag = [[alertView textFieldAtIndex:0] text];
if (buttonIndex == 1 && newTag.length > 0) {
NSIndexPath* index = [self.collectionView indexPathsForSelectedItems][0];
[self deleteItemAt:index completion:nil];
[self addNewItemWithString:newTag completion:nil];
}
}
Maybe someone deems useful.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.