gpt4 book ai didi

ios - 加载远程图像破坏了 JSQMessagesAvatarImageFactory

转载 作者:行者123 更新时间:2023-11-29 00:25:03 25 4
gpt4 key购买 nike

当我尝试加载头像的远程图像时,应用程序崩溃并出现错误,提示我的图像不能为零。我暂时只是在 ViewDidLoad 方法中添加头像创建

- (void)viewDidLoad {
[super viewDidLoad];

self.inputToolbar.contentView.textView.pasteDelegate = self;
self.userAvatarDictionary = [[NSMutableDictionary alloc] init];
self.latestGuid = @"";

/**
* Load up our fake data for the demo
*/
self.demoData = [[DemoModelData alloc] init];

/**
* You can set custom avatar sizes
*/

self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeMake(30, 30);

self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero;

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage jsq_defaultTypingIndicatorImage]
style:UIBarButtonItemStylePlain
target:self
action:@selector(receiveMessagePressed:)];


//Load remote image for Gibson Les Paul Guitar as test
NSString *imgURLString = @"http://images.gibson.com/Products/Electric-Guitars/Les-Paul/Gibson-USA/Les-Paul-Studio/Splash-02.jpg";

NSURL *url = [NSURL URLWithString:imgURLString];
NSLog(@"CREATED USER ID: 13");
NSLog(@"CREATOR IMAGE URL: %@", imgURLString);
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *dataLoadedImg = [UIImage imageWithData:data];


JSQMessagesAvatarImage *img = [JSQMessagesAvatarImageFactory avatarImageWithImage:dataLoadedImg diameter:20.0f];

[self.userAvatarDictionary setObject:img forKey:@"13"];
NSLog(@"ADDED GIBSON ICON SUCCESSFULLY");
[self callViewMessagesListWithLatestMessageGuid:self.latestGuid
CompletionBlock:^(NSMutableArray *resultsArray) {
[self reloadData:resultsArray];
}];
[NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(fifteenSecondsPassed:) userInfo:nil repeats:YES];
}

应用程序在到达成功日志之前就崩溃了,并且显然没有调用消息加载 Web 服务。

Logging/Error messaging:

CREATED USER ID: 13
CREATOR IMAGE URL: http://images.gibson.com/Products/Electric-Guitars/Les-Paul/Gibson-USA/Les-Paul-Studio/Splash-02.jpg

*** Assertion failure in +[JSQMessagesAvatarImageFactory jsq_circularImage:withDiameter:highlightedColor:], /Users/propstm/Documents/Github/MyProject/Pods/JSQMessagesViewController/JSQMessagesViewController/Factories/JSQMessagesAvatarImageFactory.m:132
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: image != nil'

最佳答案

这是因为您的图像没有在 View 需要时加载。这可以通过使用默认图像来解决,直到您可以恢复图像。您可以创建一个方法来为您提供您最初使用的默认空白头像,然后如果您的请求返回更新该单元格的头像。

func getBlankAvatar() -> UIImage {
let blankAvatar = JSQMessagesAvatarImageFactory.avatarImageWithUserInitials("?", backgroundColor: .gray, textColor: .white, font: UIFont.systemFontOfSize(14), diameter: UInt(kJSQMessagesCollectionViewAvatarSizeDefault))

另外,如果您为对话中的用户创建字典并为他们获取远程图像并将其保存到该字典中,那么作为优化,您只需发出一次请求,就可以从该字典中提取您的个人消息单元格.

🖖🏽

关于ios - 加载远程图像破坏了 JSQMessagesAvatarImageFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43235174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com