The selected events in a tableview, I pop a subView
- (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
myViewController * ViewController = [[myViewController alloc] initWithNibName: @ "myViewController" bundle: nil];
/ / [Self.navigationController pushViewController: ViewController animated: YES];
[Self.view addSubview: ViewController.view];
Then subView I perform
- (IBAction) remove: (id) sender
{
[Self.view removeFromSuperview];
}
The result is the entire app is closed and not closed subView, where the back view tableView
Reply:
You try
[ViewController.view removeFromSuperview];
Reply:
This is the collapse of the bar
Reply:
Identify the reasons
myViewController * ViewController = [[myViewController alloc] initWithNibName: @ "myViewController" bundle: nil];
/ / [Self.navigationController pushViewController: ViewController animated: YES];
[Self.view addSubview: ViewController.view];
Here I finally added a [ViewController release];
According to memory management method, because viewcontroller is alloc allocation, so to release themselves.
But more than a sentence but wrong, whether to perform a [self.view removeFromSuperview] in subView in;
Also in subView, remove the [super dealloc] is also running, but there will be a compiler warning.
Will also release ViewCntroller, or ViewController did not actually release?
By the way, this code is when a row is selected tableView, excited. I wonder if with tableView related.
Reply:
Really is collapsed.
Cause of the crash is that you call release right.
First, your understanding is wrong.
You alloc, and you will be responsible in the end, you want to call release, does not release its own.
Can not remove super dalloc (removed some things have not released)
viewcontroller did not release, you tap, a memory leak.
And tableview irrelevant.
addsubview not the same and push, push can release, because it retain the interior, addsubview not be able to, because controller is gone, view nor can it.
If you do not want to push, can be used to make a member variable to manage, let him retain, you can call release it.
Reply:
Puzzled, really would leak it?
Reference:
http://www.cocoachina.com/bbs/simple/?t30187.html
http://heidianfeng.blog.163.com/blog/static/618434562010103010817882/
myViewController * ViewController = [[myViewController alloc] initWithNibName: @ "myViewController" bundle: nil]; / / ViewController retaincount +1
[Self.view addSubview: ViewController.view]; / / here also will be retain, the question is who is retain, ViewController? Or ViewController.view?
[ViewController release] ;/ / program from the Internet to find the multi-view, no sentence, but according to the memory management rules, is the release
Engage giddy, experts advise.
Reply:
According to the official statement, addsubview, retain the view.
http://developer.apple.com/library/ios/ # documentation / UIKit / Reference / UIView_Class / UIView / UIView.html
addSubview:
Adds a view to the end of the receiver's list of subviews.
- (Void) addSubview: (UIView *) view
Parameters
view
The view to be added. This view is retained by the receiver. After being added, this view appears on top of any other subviews.
Discussion
This method retains view and sets the view's next responder to the receiver, which is its new superview.
Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.
addsubview the retain, release do we deal with.
The problem is, we alloc, and then release, do wrong?
Reply:
The two operations are linked view is good. release all view.
You alloc controller, addview (retainview), then release controller (the view of the house were demolished, but also to let live)
Have not mastered basic concepts
Impatient.
But I answer at midnight, 5:30 on you up, also considered a more fierce.
Reply:
Indeed, I have not mastered basic concepts very well. Learning objective-c it these days, nor how learned C, especially not used to manually release the memory.
You mean I can only speculate about.
controller has a view of the property points to view, when contrller is released, the view point can not be found. So will cause the program to crash.
According to your statement, the controller as a member variable, @ property when retain once, then need to release in dealloc once. Then initialize the controller needs to alloc, then it also needs to re-release in dealloc once, that is, release twice?
Reply:
Also, I see online is a saying that the [self.view removeFromSuperview];
In fact, just the view hidden and not released, does it still need to release the view?
No comments:
Post a Comment