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
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
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
.