释放 UIView 对象后不调用 TouchBegan

发布于 2025-01-05 00:26:34 字数 833 浏览 2 评论 0原文

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

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

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

这是我的代码:

插入 UIViewController。 OTTestResult 是 UIView 的控制器:

-(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 对象中的 TouchBegan 实现:

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

有人知道我做错了什么吗?

谢谢。

I'm implementing an UIView with touchesBegan method.

When I create this UIView without releasing after add in subviews collection, all works fine.

But, when I'm a good citizen and I release the object after adding in subviews, the touches begans is not called.

This is my code:

Inserting UIViewController. OTTestResult is the Controller of the UIView:

-(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];

}

And touchesBegan implementation in OTTestResult object:

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

Anyone knows what I'm doing wrong?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2025-01-12 00:26:34

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

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

But, when I'm a good citizen and I release the object after adding in subviews, the touches begans is not called.

You did not add result to subviews. You added result.view. You then released result, which no one else is holding, and it deallocated. You will need to hold onto the sub-view controller in an ivar if you need it to stay around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文