Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Storyboard and creating tagArray.... #14

Open
rjpalermo1 opened this issue Nov 28, 2015 · 0 comments
Open

Using Storyboard and creating tagArray.... #14

rjpalermo1 opened this issue Nov 28, 2015 · 0 comments

Comments

@rjpalermo1
Copy link

Nice control.

FYI I'm not by any means a programmer so after a few hours of banging the keyboard on trying to implement this control in storyboard UIScrollView, I wanted to let anyone struggling like me on how to implement this and capture the selected and added tags in an array...

  1. Add TLSTagControl.h & TLSTagControl.m in you project
  2. Add the to your interface
  3. Create an NSArray object in your interface
// This hold the array of pre-defined tags a user can select
*     NSArray *customerTagArray;
  1. Drag 2 UIScroll views on your storyboard and create IBOutlets for each:

    // This is the UIScrollView that will populate with selected tags and new tags the user can add

  • @Property (strong, nonatomic) IBOutlet TLTagsControl *selectedTagView;

    // This is the UIScrollView that provides user pre-defined tags to select
    *@Property (strong, nonatomic) IBOutlet TLTagsControl *tagView;

  1. In your viewController.m viewDidLoad:
      // This is the UIScrollView that will populate with selected tags and new tags the user can add
      _selectedTagView.mode = TLTagsControlModeEdit;
      _selectedTagView.tagPlaceholder = @"Add Tag";
     [_selectedTagView reloadTagSubviews];

      // This is the UIScrollView that provides user pre-defined tags to select
      _viewCustomerTags.mode = TLTagsControlModeList;
     customerTagArray = [NSMutableArray arrayWithArray:@[@"A", @"Tag", @"One", @"More", @"Tag", @"And", @"Yet", @"Another", @"One"]];
      _viewCustomerTags.tags = [customerTagArray mutableCopy];
     [_viewCustomerTags reloadTagSubviews];
     [_viewCustomerTags setTapDelegate:self];
  1. In your viewController.m add this delegate method:
  • (void)tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index {
    NSLog(@"Tag "%@" was tapped", tagsControl.tags[index]);
    if (!_selectedTagView.tags containsObject:tagsControl.tags[index]]) {
    [_selectedTagView.tags insertObject:tagsControl.tags[index] atIndex:0];
    [_selectedTagView reloadTagSubviews];
    } else {
    [_selectedTagView.tags removeObject:tagsControl.tags[index]];
    [_selectedTagView reloadTagSubviews];
    }
    }
  1. Your selected tags array is the _viewNewTags.tags array.
  • You can add an NSLog(@"Selected Tags %@", _selectedTagView.tags); to the tagsControl method and it will show the _selectedTagView.tags array whenever user selects a pre-defined tag, however I can't figure out how to log the _selectedTagView.tags array when user adds or deletes an object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant