【发布时间】:2014-12-02 13:00:35
【问题描述】:
当我使用 UIActionSheet 或 UIAlertController 执行以下操作时,我在模拟器中的 iOS 8 中看到内存泄漏。 UIActionSheet 在 IOS 8 中使用 UIAlertController,因此问题是相关的。
按下按钮时会调用 showCameraAction。我已经从委托方法中删除了所有内容,但在下面显示的情况下仍然存在泄漏。我是否以某种不应该的方式使用 UIActionSheet?我将不胜感激解决此问题的任何帮助。 IOS 7(在模拟器中)相同的代码没有泄漏。
-(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,结果相同:
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];
【问题讨论】:
-
我得到了与 UIAlertController 和 UIAlertView 类似的泄漏:stackoverflow.com/questions/26273175/…
-
@Jageen 是的。我正在使用 ARC。
-
@MartinMoizard 谢谢。那很有意思。看起来我的 UIActionSheet 在 iOS 8 的后台也使用 UIAlertController,所以它们看起来是相关的。
-
我也遇到过这个问题!它在真正的 iPad 上泄漏,模拟器仅在 iOS8.x 上查看我在 Apple 论坛中的消息devforums.apple.com/message/1099436#1099436
标签: ios memory-leaks ios8 uiactionsheet uialertcontroller