Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents
Multiple ways to create a controller and view
Load of Controller view
Create with Storyboard
1: Load Storyboard First (test is storyboard's name)
UIStoryboard *storyboard = [UIStoryboardstoryboardWithName:@"Test"bundle:nil];
2: Initialize the controller in the storyboard
Initialize the "Initial controller" (the controller that the Arrow refers to)
NYViewController *NY = [storyboard instantiateInitialViewController];
3: Initialize the corresponding controller through the? ID
NYViewController *NY = [storyboardinstantiateViewControllerWithIdentifier:@”NY"];
Code directly created
NYViewController *ny = [[NYViewController alloc] init];
Specify Xib. File to create
NYViewController *ny = [[NYViewController alloc]initWithNibName:@”NYViewController" bundle:nil];
Multi-Controller
iOS apps are rarely made up of a single controller, unless the app is extremely simple, and when there are multiple controllers in the app, we need to manage these controllers, as well as the controller:
Use 1 controllers to manage multiple other controllers.
比如:?一个控制器A去管理3个控制器B、C、D 控制器A被称为控制器B、C、D的“?父控制器” 控制器B、C、D的被称为控制器A的“?子控制器”
To facilitate the management of the Controller, iOS offers 2 more special controllers
**
? Uinavigationcontroller
? Uitabbarcontroller
**
Delay Loading of Controller view:
控制器view的延迟加载:控制器的view是延迟加载的:用到时再加载。可以用isViewLoaded?法判断一个UIViewController的view是否已经被加载。控制器的view加载完毕就会调用viewDidLoad方法。
Uinavigationcontroller
With Uinavigationcontroller, you can easily manage multiple controllers, easily switch between controllers, the typical example is the system comes with the "settings" should?
Uinavigationcontroller Steps to use
1: Initialize Uinavigationcontroller
2: Set UIWindow's Rootviewcontroller to Uinavigationcontroller
3: Add the corresponding number of sub-controllers by push method according to the specific situation
Uinavigationcontroller features of the sub-controller
1:uinavigationcontroller to save the sub-controller in the form of a stack
@property(nonatomicNSArray@property(nonatomic,readonlyNSArray *childViewControllers;
2: Use push method to push a controller into the stack
- (void)pushViewController:(UIViewController *)viewControlleranimated:(BOOL)animated;
3: Enable the Pop method to remove the controller
Remove the controller from the top of the stack
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
Back to the specified? Child controller
- (NSArray *)popToViewController:(UIViewController*)viewController animated:(BOOL)animated;
Back to root controller (stack bottom controller)
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
Uinavigationbar content Settings How to modify the contents of the navigation bar
The contents of the navigation bar are determined by the Navigationitem property of the stack top controller Uinavigationitem has the following properties affecting the contents of the navigation bar.
1: Back button in upper left corner
@property(nonatomicUIBarButtonItem *backBarButtonItem;
2: The middle title view
@property(nonatomicUIView
3: The middle title? text
@property(nonatomicNSString *title;
4: View in upper-left corner
@property(nonatomicUIBarButtonItem *leftBarButtonItem;
5:uibarbuttonitem *rightbarbuttonitem view in the upper right corner
@property(nonatomicUIBarButtonItem *rightBarButtonItem;
Segue
Storyboard on the top of each of the lines used for interface jumps, is a Uistoryboardsegue object (abbreviated segue)
Properties of the Segue
Each of the Segue objects has 3 properties
1: Unique identification
@property (nonatomicreadonlyNSString *identifier;
2: Source Controller
@property (nonatomicreadonlyid sourceViewController;
3: Target Controller
@property (nonatomicreadonlyid destinationViewController;
Types of Segue
According to segue execution (jump) moment, segue can be divided into 2? Large type
1: Automatic type: After clicking on a control (like a button), the automatic execution of segue, the completion of the boundary jump.
● 按住Control键,直接从控件拖线到目标控制器例如: 点击“登录”按钮后,就会自动跳转到右边的控制器,如果点击某个控件后,不需要做任何判断,一定要跳转到下一个界?面,建议使?用“?动型Segue”
2: Manual type: Need to write code manually? Segue to complete the interface jump.
Control-Drag the line from the source controller to the target controller
Unique identifiers are required:
At the right moment, use the Perform method to perform the corresponding segue
[selfperformSegueWithIdentifier:@"login2contacts"sender:nil];//Segue必须由来源控制器来执行,也就是说,这个perform?法必须由来源控制器来调?
If you click on a control, you need to make some judgments, that is to say: to meet the conditions to jump to the next sector?, the proposed use of "segue"
So whether to judge or not to jump directly, is to judge the use of that type of segue important criteria.
Performseguewithidentifier:sender:
1: The use of Performseguewithidentifier: The law can be used to do a segue, complete the interface jump.
2:performseguewithidentifier:sender: The complete process of law enforcement
[selfperformSegueWithIdentifier:sender:nil];// 这个self是来源控制器
3: According to identifier to find the corresponding line in storyboard, new Uistoryboardsegue object
? Set the Sourceviewcontroller of the Segue object (source Controller)
? New and set the Segue object's Destinationviewcontroller (??? controller)
4: Call Sourceviewcontroller The following method, do some pre-jump preparation and pass in the creation of a good Segue object
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender: (id)sender;// 这个sender是当初performSegueWithIdentifier:sender:中传?入的sender
5: Tune? Segue Object-(void) perform; method to start the interface jump operation
? Get the Uinavigationcontroller where Sourceviewcontroller is located
? The Uinavigationcontroller push method pushes the destinationviewcontroller into the stack and completes the jump.
Data transfer of the Controller
Principle: Transfer of sender parameters
[self performSegueWithIdentifier:@“login2contacts” sender:@“jack”];//@“jack”指的是下面的sender//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
There are 2 main cases of data transfer between controllers: smooth and reverse transmission
? Shun Chuan
Controller Jump Direction: A – "C
Direction of data transfer: A – "C
Data transfer method: In a Prepareforsegue:sender:? Method according to the Segue parameter obtained Destinationviewcontroller, that is, controller C, directly to the Controller C pass data
(To get data in C's viewdidload, to assign values to UI controls on the bounds)
? Reverse transmission
The controller jumps to: A – "C
Data transfer? To: C – "A
Data transfer: Let a become the agent of C, call a agent in C, through the parameters of the proxy method to pass the data to a.
Extended
Uitabbarcontroller:
Similar to Uinavigationcontroller, Uitabbarcontroller can easily manage multiple controllers, easily switch between controllers, the typical example is QQ, etc.
The life cycle method of the Controller
A simple diagram: The methods are all inside
PS: New iOS Exchange Learning Group: 304570962 can add cat qq:1764541256 or Znycat Let's study hard together.
Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents
Cat learning iOS (23) UI Controller Management