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
推荐答案
我建议在 iOS8 中使用UIAlertController".并从呈现的控制器中解除 alertController 对象,通过UIAlertAction"块触发任何事件.
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屋!