I am creating a section containing control within my viewDidLoad method, such as:
< Code> NSArray * tabits = [NSARRAAR with object: @ "one", @ "two", zero]; UISegmentedControl * Tab = [[UISegmentedControl alloc] initWithItems: tabitems]; Tabs.segmentedControlStyle = UISegmentedControlStyleBar; Tabs.frame = CGRectMake (185.0, 7.0, 130.0, 30.0); Tabs.selectedSegmentIndex = 0; [Self. Navigation Controller Add navigation bar link view: tab]; [Tab release];
But when the user goes back to the UIVGuigrator hierarchy, the controller with the segment lives on the navigation bar. How can I get rid of it? Or am I fundamentally doing something wrong?
Edit
After Alex's suggestions, I submitted the tabs and tried:
NSArray * tabItems = [NSARRAARO With Objects: @ "FAQs", @ "Rules", Zero]; Self.tabs = [[[UISegmentedControl alloc] initWithItems: tabItems];
But I'm not sure that this is a good idea to allocate an asset;
And I
[self.tabs removeFromSuperview];
I think delays are enough, is it enough?
Refer to the split controls in your view controller (i.e. defined tab
view As a property in the controller's header file).
Override the view controller's method, and by using the method of control, remove the block containing the control from the navigation bar.
Edit
You can still alloc-init
in your sagged control tab
-viewDidLoad
. You need to set up a retaining property for the tab
in the header of your view controller, and see dealloc
in the control control
release < / Code> Transfer the statement.
Read the "Properties" section for introduction of properties and how to set them up.
The method to override the method is as follows:
- (returnclass) methodname: nightOverride: algos {[super ordinate override: args]; // your code goes here ...}
in the case of -viewWillDisappear:
, this method is called when your view controller disappears As it turns off the navigation stack, it's a great place to put this code, which clears view-controller-specific items like your segment control:
- (Zero) viewview size: (BOOL) animated {[super visual shape: animated]; [Remove tabspro preview]; } If your property is set as follows: @property (nonatomic , Retaining) UISegmentedControl * Tab;
Then you are going to retaining
is equivalent to self.tabs
.
Your code is here:
Self-Tabs = [[UGidined Control Elok] Init With ITEMs: ...];
will create a memory leak because you keep this object: [[UISegmentedControl alloc] init]
- but you never release Doing [[UISegmentedControl alloc] Init] itself
this is bad.
Instead, use autorelease
on the right side, that is:
self.tabs = [[[UISegmentedControl alloc] initWithItems:. ..] autoresage];
tab
property retains its own context of control with the initial section, the control with the initial section has been released exactly at some later point. So there is no more memory leak.
Comments
Post a Comment