AMTagListView removeTag problem
etamity opened this issue · 5 comments
Hi,
I was trying to use two AMTagListView, for example ,AMTagListView1 and AMTagListView2,
when I click one AMTagListView1 , removeTag on AMTagListView1, and add this tag to AMTagListView2, but it's not working properly, can you have a check with this issue?
Thanks
Can you post some sample code to reproduce the issue? And maybe specify what do you mean by not working properly
Hi Andreamazz,
Thank you for replying quickly.
The problem is , when I try to remove the tag, the tag is always not removed, and it will add on the tail of the view list.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.hotTagsData=[[NSMutableArray alloc] initWithArray:self.tagsData];
self.myTagsData=[[NSMutableArray alloc] initWithArray:[[UserApi currentUser] objectForKey:@"tags"]];
[self.hotTags addTags:self.hotTagsData];
[self.myTags addTags:self.myTagsData];
MyWantsPageController* weakSelf = self;
[self.hotTags setTapHandler:^(AMTagView *view) {
[weakSelf.myTags addTag:view.tagText];
[weakSelf.hotTags removeTag:view];
}];
[self.myTags setTapHandler:^(AMTagView *view) {
[weakSelf.hotTags addTag:view.tagText];
[weakSelf.myTags removeTag:view];
}];
}
I created two AMTagListView
one is tagListView, another is list1,
and try to exchange the tags when you click, but it's not working properly.
//
// AMViewController.m
// TagListViewDemo
//
// Created by Andrea Mazzini on 20/01/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
//
#import "AMViewController.h"
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@interface AMViewController () <UITextFieldDelegate, UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet AMTagListView *tagListView;
@property (weak, nonatomic) IBOutlet AMTagListView *list1;
@property (nonatomic, strong) AMTagView *selection;
@end
@implementation AMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:@"Demo"];
[self.textField.layer setBorderColor:UIColorFromRGB(0x1f8dd6).CGColor];
[self.textField.layer setBorderWidth:2];
[self.textField setDelegate:self];
[[AMTagView appearance] setTagLength:10];
[[AMTagView appearance] setTextPadding:14];
[[AMTagView appearance] setTextFont:[UIFont fontWithName:@"Futura" size:14]];
[[AMTagView appearance] setTagColor:UIColorFromRGB(0x1f8dd6)];
[self.tagListView addTag:@"my tag"];
[self.tagListView addTag:@"something"];
[self.tagListView addTag:@"long tag is long"];
[self.tagListView addTag:@"hi there"];
[self.view addSubview:self.tagListView];
__weak AMViewController* weakSelf = self;
[self.list1 setTapHandler:^(AMTagView *view) {
[weakSelf.tagListView addTagView:view];
[weakSelf.list1 removeTag:view];
}];
[self.tagListView setTapHandler:^(AMTagView *view) {
[weakSelf.list1 addTagView:view];
[weakSelf.tagListView removeTag:view];
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex > 0) {
[self.tagListView removeTag:self.selection];
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.tagListView addTag:textField.text];
[self.textField setText:@""];
return YES;
}
// Close the keyboard when the user taps away froma textfield
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UITextField class]])
[view resignFirstResponder];
}
}
@end
Got it, the tag view was set up to respond to every touch notification. Now I restricted it to its child nodes. Checkout last commit and do something like this:
__weak AMViewController* weakSelf = self;
[self.tagListView setTapHandler:^(AMTagView *view) {
[weakSelf.tagListView removeTag:view];
[weakSelf.tag2 addTagView:view];
}];
[self.tag2 setTapHandler:^(AMTagView *view) {
[weakSelf.tag2 removeTag:view];
[weakSelf.tagListView addTagView:view];
}];
Nice , its fixed !! Thank you !!