A simple way to implement page jumps in IOS application development Note _ios

Source: Internet
Author: User

As a new handwritten note, it is convenient for you to remember:

From Android to the iOS, for the page jump, looking for a lot of information, now record the page jump method.

1. With Navigationcontroller

2. Jump directly (just found on the internet, not too familiar, wrong Mo Strange)


1. Build a Rootviewcontroller, in delegate.h

Copy Code code as follows:

@property (Strong, nonatomic) Uiviewcontroller *viewcontroller;
@property (Strong, nonatomic) Uinavigationcontroller *navcontroller;

Write code in the DELEGATE.M code didfinishlaunchingwithoptions function:

Rootviewcontroller *rootview = [[Rootviewcontroller alloc] init];
Rootview.title = @ "Root View";

Self.navcontroller = [[Uinavigationcontroller alloc] init];

[Self.navcontroller Pushviewcontroller:rootview Animated:yes];
[Self.window AddSubview:self.navController.view];


The code loads the first page Rootviewcontroller.
Jump to another page (such as Subviewcontroller) code:
Copy Code code as follows:

Subviewcontroller *subview = [[Subviewcontroller alloc] init];
[Self.navigationcontroller Pushviewcontroller:subview Animated:yes];
Subview.title = @ "Sub";

The benefit is that the return button is automatically generated.


2. Direct jump, nothing

Do not need to do other redundant, directly create a View object

Copy Code code as follows:

Subviewcontroller *subview = [[Subviewcontroller alloc] initwithnibname:@ "Subviewcontroller" Bundle:[NSBundle Mainbundle]];
[Self Presentmodalviewcontroller:subview animated:yes];

That's good.

iOS6.0 doesn't use this function after all.

Copy Code code as follows:

[Self Presentmodalviewcontroller:subview animated:yes];

Can replace
Copy Code code as follows:

[Self Presentviewcontroller:subview animated:yes completion:nil];

Data transfer when a page jumps
For example, in the need to implement View1 jump to View2, the view1 of some of the data passed to View2

Ideas:

1. Customize a bean class user and implement user as a member variable in VIEW2.

2.view1 the data into user when it jumps, and assigns it to View2.user

Code

1. View2

. h declaring member variables

Copy Code code as follows:

@property (Strong, nonatomic) User *user;

2. View1

Copy Code code as follows:

View2 *view2 = [[View2 alloc] init];
User *user = [[User alloc] init];
User.Name = @ "Kevin";
View2.user = user;
[Self.navigationcontroller Pushviewcontroller:view2
Animated:yes];

3. View2

Take the variable

Copy Code code as follows:

Self.user.name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.