IOS UI07 _ navigation View Controller
//// MainViewController. m // UI07 _ navigation View Controller /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import MainViewController. h # import SecondViewController. h @ interface MainViewController () @ property (nonatomic, retain) UITextField * textfield; @ end @ implementation MainViewController-(void) dealloc {[_ textfield release]; [super dealloc];} -(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor cyanColor]; // The height of the Controller in the navigation view is 44 and the status bar is 20. The default value is 64 UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (200,100,100, 40); [button setTitle: @ next page forState: UIControlStateNormal]; button. layer. borderWidth = 1; button. layer. cornerRadius = 10; [self. view addSubview: button]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; // set the navigation view Controller // Add a title/self. title = @; // appearance setting // background color. Not all background colors are backgroundColor // self. navigationController. navigationBar. barTintColor = [UIColor greenColor]; // create a UIview UIView * view = [[UIView alloc] initWithFrame: CGRectMake (0, 0,100,100)]; view. backgroundColor = [UIColor blackColor]; [self. view addSubview: view]; [view release]; // to prevent coordinate system tampering, we set bar from translucent to opaque, so that the origin of the coordinate system is automatically pushed down 64 self. navigationController. navigationBar. translucent = NO; // set the content in it // set the title self. navigationItem. title = @; // specify some views, called titleView UISegmentedControl * seg = [[UISegmentedControl alloc] initWithItems: @ [@, @ ]; self. navigationItem. titleView = seg; // create button self on both sides. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target: self action: @ selector (leftButtonAction :)] autorelease]; // self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @ Tianping .png] style: UIBarButtonItemStylePlain target: self action: @ selector (right :)]; // create a small button UIButton * rightButton = [UIButton buttonWithType: UIButtonTypeCustom]; rightButton. frame = CGRectMake (0, 0, 40, 40); [rightButton setImage: [UIImage imageNamed: @ Tianping .png] forState: UIControlStateNormal]; self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: rightButton]; self. textfield = [[UITextField alloc] initWithFrame: CGRectMake (100,200,100, 40)]; self. textfield. layer. borderWidth = 1; self. textfield. layer. cornerRadius = 10; [self. view addSubview: self. textfield]; [self. textfield release];}-(void) leftButtonAction :( UIBarButtonItem *) button {}-(void) right :( UIBarButtonItem *) button {}-(void) click :( UIButton *) button {// jump to the next page using the modal mode // SecondViewController * secondVC = [[SecondViewController alloc] init]; // [secondVC setModalTransitionStyle: Second]; // [self presentViewController: secondVC animated: YES completion: ^ {//}]; // use the Navigation View Controller Navigation to redirect. // first create the next page object SecondViewController * secVC = [[SecondViewController alloc] init]; // set the attribute value to the second step secVC. number = 100; secVC. str = self. textfield. text; secVC. arr = @ [@ Yang Lin, @ Liu Shan]; // [self. navigationController pushViewController: secVC animated: YES]; // memory management [secVC release];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end
//// SecondViewController. h // UI07 _ navigation View Controller /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import
@ Interface SecondViewController: UIViewController // The first step for passing the attribute value. On the second page, write an attribute @ property (nonatomic, assign) NSInteger number; // write an attribute @ property (nonatomic, copy) NSString * str; @ property (nonatomic, retain) NSArray * arr; @ end
//// SecondViewController. m // UI07 _ navigation View Controller /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import SecondViewController. h # import ThirdViewController. h @ interface SecondViewController () @ property (nonatomic, retain) UILabel * label; @ end @ implementation SecondViewController-(void) dealloc {[_ label release]; [super dealloc]; [_ arr release]; [_ str release];}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor orangeColor]; UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (200,100,100, 40); [button setTitle: @ next page forState: UIControlStateNormal]; button. layer. borderWidth = 1; button. layer. cornerRadius = 10; [self. view addSubview: button]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside]; NSLog (@ % ld, self. number); self. label = [[UILabel alloc] initWithFrame: CGRectMake (100,100, 50, 40)]; self. label. backgroundColor = [UIColor redColor]; [self. view addSubview: self. label]; [self. label release]; self. label. text = self. str; NSLog (% @, self. arr [0]);}-(void) click :( UIButton *) button {ThirdViewController * thirdVC = [[ThirdViewController alloc] init]; [self. navigationController pushViewController: thirdVC animated: YES]; [thirdVC release];}-(void) didReceiveMemoryWarning {[super ready]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end
//// ThirdViewController. m // UI07 _ navigation View Controller /// Created by dllo on 15/8/6. // Copyright (c) 2015 zhozhicheng. all rights reserved. // # import ThirdViewController. h @ interface ThirdViewController () @ end @ implementation ThirdViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. view. backgroundColor = [UIColor yellowColor]; UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem]; button. frame = CGRectMake (200,100,100, 40); [button setTitle: @ return forState: UIControlStateNormal]; button. layer. borderWidth = 1; button. layer. cornerRadius = 10; [self. view addSubview: button]; [button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside];}-(void) click :( UIButton *) button {// jump forward from the back [self. navigationController popToRootViewControllerAnimated: YES]; // jump to the previous page // [self. navigationController popViewControllerAnimated: YES];}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} * // @ end