2017-06-20 26 views
0

我正在嘗試在Objective-C中進行聊天App。在目標c中標記WhatsApp的邏輯

在這個我想實現像WhatsApp標籤。

當用戶在組中輸入@時,它應顯示組成員列表。 我嘗試去做,但有時候會遇到問題,比如在「@xyz」之後進入退格時。我沒有按預期獲得產量。

你能告訴我一些例子或教程,我可以參考。

+1

歡迎StackOverflow上選擇成員。請首先看看[我可以在這裏詢問什麼主題?](https://stackoverflow.com/help/on-topic) – andih

回答

0

試試這個簡單,

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    textViews.delegate = self; 
    namesArray = @[@"John",@"Mathew」,@「iOS」]; 
    membersTable.hidden = true; 

    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)textViewDidChange:(UITextView *)textView { // Delegate method called when any text is modified 

    if ([textViews.text isEqualToString: @""]) { 

     membersTable.hidden = true; 
    }else{ 

     if ([[textView.text substringFromIndex: [textView.text length] - 1] isEqualToString:@"@"]) { 
      NSLog(@"Success"); 
      membersTable.hidden = false; 
     }else{ 
      membersTable.hidden = true; 
     } 
    } 

} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return namesArray.count; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [membersTable dequeueReusableCellWithIdentifier:@"cell"]; 
    cell.textLabel.text =[namesArray objectAtIndex:indexPath.row]; 

    return cell; 
} 

成員的tableView會當用戶輸入顯示「@」符號在你的TextView然後用戶可以通過選擇的tableView