释放 UIView 对象后不调用 TouchBegan
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有将
结果
添加到子视图
。您添加了result.view
。然后,您释放了没有其他人持有的result
,并将其释放。如果您需要保留子视图控制器,则需要将其保留在 ivar 中。You did not add
result
tosubviews
. You addedresult.view
. You then releasedresult
, 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.