Notes on simple ways to realize page jumps in iOS application development
- 2020-05-17 06:34:50
- OfStack
As a new handwritten note, easy to remember:
From android to iOS, for the page jump, found a lot of information, now record 1 page jump method.
1. Use navigationController
2. Jump right in (I just found it on the Internet, it's not very familiar, I don't blame you)
1. Build an RootViewController at delegate.h
@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UINavigationController *navController;
delegate.m code didFinishLaunchingWithOptions Write code in the 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];
This code loads the first page, RootViewController.
Jump to another page (such as SubViewController) code:
SubViewController *subView = [[SubViewController alloc] init];
[self.navigationController pushViewController:subView animated:YES];
subView.title = @"Sub";
The advantage is that the back button is automatically generated.
2. Jump straight to nothing
Instead of doing anything else, create a new view object
SubViewController *subView = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:subView animated:YES];
That's it.
iOS 6.0 doesn't even use this function anymore
[self presentModalViewController:subView animated:YES];
Can be replaced by
[self presentViewController:subView animated:YES completion:nil];
The transfer of data when a page jumps
For example, if you need to implement view1 to jump to view2, pass some data of view1 to view2
Ideas:
1. Customize one bean class user, and implement user as a member variable in view2.
2. When jumping view1, the data is encapsulated as user and assigned to view2.user
code
1. view2
.h declares member variables
@property (strong, nonatomic) User *user;
2. view1
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 to the variable
self.user.name