iOS 8仅使用UIAlertController或UIActionSheet进行内存泄漏 [英] iOS 8 Only Memory Leak with UIAlertController or UIActionSheet
问题描述
当我使用UIActionSheet或UIAlertController执行以下操作时,我在模拟器中看到iOS 8中的内存泄漏。 UIActionSheet在IOS 8中使用UIAlertController,因此问题是相关的。
I'm seeing a memory leak in iOS 8 in simulator when I do the following with UIActionSheet or UIAlertController. UIActionSheet uses UIAlertController in IOS 8 so the issues are related.
按下按钮时会调用showCameraAction。我已从委托方法中删除了所有内容,但在下面显示的情况下仍然会出现泄漏。我是否以某种方式使用UIActionSheet,我不应该这样做?我将非常感谢您解决此问题的任何帮助。相同的代码没有IOS 7泄漏(在模拟器中)。
showCameraAction gets called when a button is pressed. I've removed all of the content from the delegate method and still get the leak in the case shown below. Am I using UIActionSheet in some way that I shouldn't? I would appreciate any help in resolving this issue. The same code has no leaks with IOS 7 (in the simulator).
-(IBAction)showCameraAction:(id)sender
{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Photo From:"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Phone", @"Flickr", nil];
[actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
//also tried just showInView: self.view
}
//空
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
}
也尝试使用UIAlertController,结果相同:
Also tried with UIAlertController, with the same result:
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Photo From:"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *phoneAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Phone", @"Phone action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Phone action");
}];
UIAlertAction *flickrAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Flickr", @"Flickr action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Flickr action");
}];
[alertController addAction:phoneAction];
[alertController addAction:flickrAction];
[self presentViewController:alertController animated:YES completion:nil];
带有跟踪的屏幕截图: https:// www .dropbox.com / l / FmnTCd0PvVhuu16BVHZo7p
Screenshot with trace: https://www.dropbox.com/l/FmnTCd0PvVhuu16BVHZo7p
推荐答案
我建议在iOS8中使用UIAlertController。
并且在通过UIAlertAction块触发任何事件时,从呈现的控制器中解除alertController对象
。
I would suggest to use "UIAlertController" in iOS8. And dismiss the alertController object from the presented controller, while firing any event by "UIAlertAction" block.
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title"
message:@"message"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"actionTitle"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
//Do ur stuff
[alertController dismissViewControllerAnimated:YES
completion:NULL];
}];
[alertController addAction:alertAction];
[self presentViewController:alertController
animated:YES
completion:NULL];
这篇关于iOS 8仅使用UIAlertController或UIActionSheet进行内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!