kas-kad / AKTagsInputView

convenient input view for tags strings
Apache License 2.0
85 stars 20 forks source link

Simple editing the tags #23

Closed ghostiam closed 9 years ago

ghostiam commented 9 years ago
  1. Enable always the delete button:
    • open file AKTagCell.m
    • delete _deleteButton.enabled = selected; from -(void)setSelected:(BOOL)selected
    • replace _deleteButton.enabled = NO; on _deleteButton.enabled = YES; from -(UIButton *)deleteButton
  2. Add next code to the file 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.

kas-kad commented 9 years ago

Hi, If you'd like to help to improve the original codebase, there are more important issues https://github.com/purrrminator/AKTagsInputView/labels/enhancement