开发者

[Not A Type release]: message sent to deallocated instance 0x5853f00

[Not A 开发者_运维问答Type release]: message sent to deallocated instance 0x5853f00 getting this error please help when adding a view

AnotherView* obj = [[AnotherView alloc] init];
[self.view addSubview:obj.view];
[obj release];


You are adding [UIView view] to the current view. There is no view property inside UIView.

As pointed out, you should add the UIView object itself.

In an OpenGL context, you should also consider what the docs say:

Note: If you are using OpenGL ES to do your drawing, your view’s drawRect: method is not called. Instead, it is up to you to determine when your view needs to be redrawn and initiate the appropriate drawing updates.

So make sure your UIVIew is initialized correctly.


You generally get this error when you send a message to already released instance. So what I suspect in your code is, you created some views and then you added it to some other view and released the previous created view. Now if any action performed on the first view (which is already released) will cause the exception. i.e.: First View contains a button and action for this button's touchup inside is written in FristViewController. Now I created the instance of FirstView and added into second view and released the firstview instance. Now suppose user tap on FirstView's button then, iOS will search for controller (FirstViewController) which is already released, and this problem will occur. To get rid of the problem you can simply send autorelease message to the instance and will work fine.

The main reason of this happening is, addSubview does not take care of retain count. I hope this will help you.


You can't release obj because [self.view addSubview:obj.view] only add view of obj not entire object. If you release it and your view is visible on screen then it may possible that some message will be sent to deallocated object, so it result in crash.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜