停止在Iphone中反复重新加载UItableView

时间:2016-01-21 13:08:48

标签: ios objective-c iphone uitableview

我正在使用聊天应用,因为我使用UITableView聊天屏幕。在每个聊天气泡中,用户的个人资料照片都在那里,现在我的问题是当新消息来了或我发送新消息时整个tableView正在重新加载聊天气泡中的图像,我想阻止它,任何人都可以帮助我弄明白? 我的代码是:

- (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);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用https://github.com/rs/SDWebImage库。 在此库中,您可以使用延迟加载概念将图像直接设置为UIImageview。所以即使你每次都设置图像。它不会一次又一次地下载。

请查看以下代码。

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

[cell.avatarImage setImageWithURL:url usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
相关问题