iphone - UISegmentedControl Best Practice -
I want to create a "best" way of using an UISegmentedControl
for an iPhone Trying the application I have read some posts on Stackoverflow and have seen some people's ideas, but I can not get the best way to do this. The posts I am mentioning are:
and
It appears that the options are:
- Add each view to the IB And
- Create each subview separately in the IB, then create a container in the main view that you need.
- Set a really long or really expanded
UIView
and make it alive to the left / right or top / bottom depending on the selected segment - One < For classes> UITabBarController tables, for tables,
- reload the table and
cellForRowAtIndex
and sections based on different data sources or selected segmentation options Populate. Case for my app)
Which approach is best for a subview / non-table approach? Which easy to implement? Can you share some sample code in the approach?
Thank you!
Go along with the other option you specify, create subviews in IB and swapping them in and out of main view do. This will be a good opportunity to use UIViewController
, unsubclassed: In your initial setup, create a controller using -initWithNibName: bundle:
(where the first parameter is named NIB, which has a personal subview, and the other parameter is zero
) and add the code as necessary to the subview of your main view, it will help to keep your memory footprint low: getting a memory alert To see the default behavior of the UIViewController
if it does not have any supervisor, you can keep the controller in memory and release any of the sequences hidden from the visible hierarchy. Can not worry.
(Edited in response to comment :)
You do not need the don sub code to be UIViewController
, but you are different for each view XIB requires that you do not need to add anything to the view in the IB.
The Instance variable, which is handling all this in the interface of the class:
UIViewController * controllerOne; UIViewController * Controller; UIViewController * currentController; IBotlet UIView * The Contributor View;
In your setup ( -applicationDidFinishLaunching:
or whatever)
administratoron = [[UIViewController alloc] initWithNibName: @ "MyFirstView" bundle: zero]; Controller two = [[UIViewController alloc] initWithNibName: @ "MySecondView" bundle: zero];
To switch to a controller:
- (zero) switchtoo controller: (UIViewController *) newCtl {if (newCtl == current controller) Return; If ([current controller is uploaded]) [currentController.view removeFromSuperview]; If (newCtl! = Zero) [see The Container Add Sueview: New CTL. Weave]; CurrentController = newCtl; }
Then just call it, e.g.,
[Auto switchtouter: controller];
Comments
Post a Comment