如何在ios quickblox聊天应用程序中将图像显示为uitableviewcell?

时间:2014-04-25 06:10:43

标签: ios chat quickblox custom-cell

我正在使用一个自定义的tableview单元格,它在聊天气泡中显示文字并且工作正常。

但我想在聊天中显示图片。

为此我正在做以下步骤:

选择并上传文件:

- (IBAction)btnAttachments:(id)sender{

self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.allowsEditing = NO;
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[self presentViewController:self.imagePicker animated:YES completion:nil];}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *imgChosen = info[UIImagePickerControllerOriginalImage];
imgChat = imgChosen;

[picker dismissViewControllerAnimated:YES completion:NULL];

// Upload new avatar to Content module
NSData *avatar = [[NSData alloc] initWithData:UIImagePNGRepresentation(imgChat)];
//
//[QBContent TUploadFile:avatar fileName:@"MyAvatar" contentType:@"image/png" isPublic:NO delegate:self];
[QBContent TUploadFile:avatar fileName:@"userChat" contentType:@"image/png" isPublic:YES delegate:self];}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissViewControllerAnimated:YES completion:NULL];

}

已完成结果:

if(result.success && [result isKindOfClass:[QBCFileUploadTaskResult class]])
    {

        QBCFileUploadTaskResult *res = (QBCFileUploadTaskResult *)result;
        NSUInteger uploadedFileID = res.uploadedBlob.ID;

        QBChatMessage *message = [[QBChatMessage alloc] init];
        message.recipientID = self.opponent.ID;

        NSMutableDictionary *msgDict = [[NSMutableDictionary alloc]init];
        [msgDict setValue:[NSNumber numberWithInt:uploadedFileID] forKey:@"fileID"];
        message.customParameters = msgDict;

        [[QBChat instance] sendMessage:message];

    }

下载文件:

- (void)chatDidReceiveMessageNotification:(NSNotification *)notification{

QBChatMessage *message = notification.userInfo[kMessage];

if(message.customParameters != nil)
{
    NSUInteger fileID = [message.customParameters[@"fileID"] integerValue];

    // download file by ID
    [QBContent TDownloadFileWithBlobID:fileID delegate:self];
}

完成结果:

if(result.success && [result isKindOfClass:[QBCFileDownloadTaskResult class]])
    {
        QBCFileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;

        if ([res file])
        {

            UIImageView* imageView = [[UIImageView alloc] initWithImage:
            [UIImage imageWithData:[res file]]];
            [self.messages addObject:imageView];

            [self.tblObj reloadData];

        }
    }

现在,如何在聊天中显示下载的图像? 告诉我有关用于显示图像的自定义单元格。

0 个答案:

没有答案