UIActionSheet块视图控制器dealloc

时间:2015-01-29 15:31:15

标签: ios objective-c memory-leaks uiactionsheet ios8.1

在我的View控制器中,我触摸按钮启动这个简单的代码

- (IBAction)tapOnButton:(UIButton *)sender
{
    UIActionSheet *act = [[UIActionSheet alloc] initWithTitle:@"test" delegate:self cancelButtonTitle:@"aa" destructiveButtonTitle:@"bb" otherButtonTitles:@"cc", nil];
    [act showFromRect:CGRectMake(50, 50, 100, 100) inView:self.view animated:YES];
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {

    }
}

我在屏幕上显示了一个动作表,点击了动作表中的任何按钮,然后关闭。

当我运行dismiss时,我的viewcontroller没有执行dealloc。 如果您没有触摸按钮并且没有打开动作表,则dealloc可以正常工作。

是一个很大的问题。有人在继续?

我在ios 8.1.3上

2 个答案:

答案 0 :(得分:2)

我在iOS 8 iPad中使用已弃用的UIActionSheet遇到了同样的问题。使用iPhone(iOS 7和iOS 8)和iOS 7 iPad,问题无法再现。

我现在测试工作的唯一解决方案是使用UIAlertController在iOS 8中显示操作表。如果使用UIAlertController,View Controller将被正确释放。

答案 1 :(得分:1)

很可能一些引用保留在视图控制器中 - 因此它没有被释放。

请尝试在委托方法中将委托明确设置为nil,如下所示:

- (IBAction)tapOnButton:(UIButton *)sender
{
    UIActionSheet *act = [[UIActionSheet alloc] initWithTitle:@"test" delegate:self cancelButtonTitle:@"aa" destructiveButtonTitle:@"bb" otherButtonTitles:@"cc", nil];
    [act showFromRect:CGRectMake(50, 50, 100, 100) inView:self.view animated:YES];
}

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {

    }
    actionSheet.delegate = nil
}