【问题标题】:touchesBegan is not called after releasing the UIView Object释放 UIView 对象后不调用 touchesBegan
【发布时间】:2012-02-13 21:21:35
【问题描述】:

我正在使用 touchesBegan 方法实现 UIView。

当我在添加子视图集合后创建此 UIView 而不释放时,一切正常。

但是,当我是一个好公民并且在添加子视图后释放对象时,不会调用 touches begins。

这是我的代码:

插入 UIViewController。 OTTestResult 是 UIView 的 Controller:

-(void)validateWasPushed:(id)sender
{
    float nota = [testQuestions getTestResults];
    int ok = [testQuestions getOkNumber];
    int fail = [testQuestions getFailNumber];

    OTTestResult *result = [[OTTestResult alloc] init];

    [self.view addSubview:result.view];

    [result loadWithNumber:nota testName:[testQuestions testName] okResponses:ok failResponses:fail];


    [result release];

}

并在 OTTestResult 对象中实现 touchesBegan:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view removeFromSuperview];
}

谁知道我做错了什么?

谢谢。

【问题讨论】:

  • 在这种情况下 self 是什么类?这段代码是否在 UIViewController 的子类中?

标签: objective-c uiview touchesbegan


【解决方案1】:

但是,当我是一个好公民并且在添加子视图后释放对象时,不会调用 touches begins。

您没有将result 添加到subviews。您添加了result.view。然后你释放了没有其他人持有的result,它被释放了。如果需要保留它,则需要在 ivar 中保留子视图控制器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多