问题描述
我在UIImageView中显示图像时遇到问题.
I have a problem with displaying image in my UIImageView.
这就是我在ShareViewController中获取图像的方式:
So this is how I get images in ShareViewController:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
for (NSItemProvider* itemProvider in ((NSExtensionItem*)self.extensionContext.inputItems[0]).attachments )
{
if([itemProvider hasItemConformingToTypeIdentifier:@"public.image"])
{
++counter;
[itemProvider loadItemForTypeIdentifier:@"public.image" options:nil completionHandler:
^(id<NSSecureCoding> item, NSError *error)
{
UIImage *sharedImage = nil;
if([(NSObject*)item isKindOfClass:[NSURL class]])
{
sharedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:(NSURL*)item]];
}
if([(NSObject*)item isKindOfClass:[UIImage class]])
{
sharedImage = (UIImage*)item;
}
if ([(NSObject *)item isKindOfClass:[NSData class]])
{
sharedImage = [UIImage imageWithData:(NSData *)item];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationDidLoadItem" object:sharedImage];
}];
}
}
}
这是我在DetailsViewController中接收通知的方式:
this is how I receive notification in DetailsViewController:
- (void)didLoadSharedImage:(NSNotification *)notification {
UIImage *sharedImage = [notification object];
[self.sharedImages addObject:sharedImage];
if (!self.theImageView.image) {
self.theImageView.image = sharedImage;
}
}
因此,此方法后没有可见的图像.我调试了它,然后看到了那个图像,但是奇怪的是,当我从DetailsViewController推送新的视图控制器然后又弹出时看到了它.只有这样,UIImageView才好像刷新了自己.
So there is no visible image after this method. I debugged it and I saw that image is there, but it's strange that I see it when I push new view controller form DetailsViewController and then pop back. Only then UIImageView seems like refresh its self.
推荐答案
您是否尝试将didLoadSharedImage执行到UIThread中.像
Did you try to execute didLoadSharedImage into UIThread. like
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.theImageView.image) {
self.theImageView.image = sharedImage;
}
})
祝你好运
这篇关于iOS 8共享扩展名显示共享图像问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!