2016-01-21 1 views
-1

Я работаю над чат-приложением, в том, что я использовал UITableView для просмотра чата. В каждом чате пользовательского профиля pic pic есть. Теперь моя проблема в том, когда приходит новое сообщение или я отправляю новое сообщение. tableView перезагружает изображения в чате, также хочу остановить его. Может ли кто-нибудь помочь мне разобраться в этом? ? мой код:Остановить перезагрузку UItableView снова и снова в Iphone

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView == self.chatTableView) 
    { 
     NSString *cellID; 
     if([[((UUMessageFrame *)(self.chatModel.dataSource[indexPath.row])) message] from] == UUMessageFromMe) 
     { 
      cellID = @"outgoing_cell"; 
     } 
     else 
     { 
      cellID = @"incoming_cell"; 
     } 
     //commented by jigar 
     // UUMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 
     // UUMessageCell *cell = [tableView]; 

     UUMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 
     if (cell == nil) { 
      cell = [[UUMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 
      cell.delegate = self; 
      if ([cellID isEqualToString:@"outgoing_cell"]) 
      { 
       //    cell.recognizer.numberOfTapsRequired 
       [cell.recognizer addTarget:self action:@selector(longPress:)]; 
      } 
     } 
     [cell setMessageFrame:self.chatModel.dataSource[indexPath.row]]; 
     NSLog(@" text message is : %@",[cell.btnContent titleForState:UIControlStateNormal]); 
     cell.btnContent.tag = indexPath.row; 
     return cell; 
    } 
    else 
    { 
     NSString *cellIdentifier;/* = isOutgoingMessage ? self.outgoingCellIdentifier : self.incomingCellIdentifier;*/ 
     if ([[self.arrTableData objectAtIndex:indexPath.row] isKindOfClass:[OTRVoice class]]) 
     { 
      OTRVoice *voice = (OTRVoice *)[self.arrTableData objectAtIndex:indexPath.row]; 
      if(![voice.fk_Tripper isEqualToString:appDelegate.account.uniqueId]) 
      { 
       cellIdentifier = self.incomingCellIdentifier; 
      } 
      else 
      { 
       cellIdentifier = self.outgoingCellIdentifier; 
      } 
     } 
     else{ 
      cellIdentifier = self.outgoingCellIdentifier; 
     } 
     @try 
     { 
      VoiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 
      cell.avatarImage.clipsToBounds = YES; 
      cell.avatarImage.layer.cornerRadius = cell.avatarImage.bounds.size.width/2.0; 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      tableview.separatorStyle = UITableViewCellSeparatorStyleNone; 
      cell.circular_ProgressView.frame = CGRectMake(cell.btnPlay.frame.origin.x-2, cell.btnPlay.frame.origin.y, 26, 26); 
      [self configureCell:cell atIndexPath:indexPath]; 
      cell.tag = indexPath.row +10000; 
      return cell; 
     } 
     @catch(NSException *e) 
     { 
      NSLog(@"Exception is : %@",e); 
     } 
    } 
} 
+0

Для загрузки изображения вы можете использовать библиотеку SDWebImage. – kb920

ответ

0

вы можете использовать https://github.com/rs/SDWebImage библиотеку. В этом lib вы можете установить изображение непосредственно на UIImageview, используя ленивую концепцию загрузки. Поэтому даже если вы задаете изображение каждый раз. он не будет загружаться снова и снова.

проверьте приведенный ниже код.

NSURL *url = [NSURL URLWithString:@"url"]; 

[cell.avatarImage setImageWithURL:url usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
+0

Я использовал то же самое, Тем не менее, когда я просматриваю изображение вверх и вниз, всегда загружается. :(Может ли у меня помочь мне, что не так с моим кодом, поскольку он занял мои 3 дня .. :( –

+0

Я ничего не нашел что вы использовали SDWebImage. –

Смежные вопросы