How to mention users with “@” in app like Instagram

前端 未结 2 1589

I am creating an app that has photo sharing, and I am trying to add in the functionality to mention (or tag) users. Twitter is what originally starting using \"@\" with a userna

相关标签:
2条回答
  • 2021-02-04 20:54

    Listen to the input on iOS. When the user types an @, followed by a character, make a call to an url on your server (/user/lookup/?username=joe for example) that routes to a view which looks up up users beginning with joe. Return it as json and display it in a dropdown.

    Source: How to mention users with "@" in app like Instagram

    0 讨论(0)
  • 2021-02-04 21:06

    You can try something like this in the UITextView delegate:

    - (void)textViewDidChange:(UITextView *)textView
    {
        _words = [self.textView.text componentsSeparatedByString:@" "];
        NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[cd] '@'"];
        NSArray* names = [_words filteredArrayUsingPredicate:predicate];
        if (_oldArray)
        {
            NSMutableSet* set1 = [NSMutableSet setWithArray:names];
            NSMutableSet* set2 = [NSMutableSet setWithArray:_oldArray];
            [set1 minusSet:set2];
            if (set1.count > 0)
                NSLog(@"Results %@", set1);
        }
        _oldArray = [[NSArray alloc] initWithArray:names];
    }
    

    where _words, _searchResults and _oldArray are NSArrays.

    0 讨论(0)
提交回复
热议问题