【发布时间】:2014-06-04 20:12:04
【问题描述】:
在底部阅读我的编辑
在我的应用程序中,我有一个UIViewController,它经常呈现一个模态UIViewController。
这没有问题
-(void)flash
{
[self performSegueWithIdentifier:SEGUE_IDENTIFIER sender:self];
}
-(void)stopFlash
{
[self dismissViewControllerAnimated:YES completion:nil]
}
但是,当用户点击共享按钮时,关闭共享对话框(只是取消或其他)并且第一个模式UIViewController应该再次出现,它只显示黑屏。
但是右边的模态UIViewController被实例化了,我可以在NSLogs看到。点击分享按钮时,我使用以下操作:
- (IBAction)share:(id)sender
{
self.shareButton.hidden = YES;
[self.buttonActivity startAnimating];
dispatch_queue_t queue = dispatch_queue_create("background", NULL);
dispatch_async(queue, ^{
NSURL *url = APP_URL;
NSString *message = SHARE_MESSAGE;
NSArray *activities = [NSArray arrayWithObjects:message, url, nil];
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:activities applicationActivities:nil];
activity.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList];
};
self.shareController = activity;
dispatch_async(dispatch_get_main_queue(), ^{
[self.buttonActivity stopAnimating];
self.shareButton.hidden = NO;
[self presentViewController:self.shareController animated:YES completion:nil];
});
});
}
编辑:
经过更多研究后,我发现问题出在UIColor 类别中,但我仍然无法修复它。我有一个类别randomon UIColor 使用一种方法:
+(UIColor *)randomColor
{
CGFloat hue = ( arc4random() % 256 / 256.0 );
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
NSLog(@"color: %@", color);
return color;
}
此方法通常只返回一个随机颜色,该颜色在UIView 上设置为背景。
出于某种原因,在我第一次打开UIActivityViewController``randomColorjust 的情况下,返回 nil。事实上,该方法中的NSLog 甚至没有被执行,因此 randomColor 方法甚至没有被调用。为什么?太疯狂了。
感谢您的帮助。
【问题讨论】:
标签: ios cocoa-touch uiactivityviewcontroller