- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
MainViewController *mainVC = [[MainViewController alloc] init];
UINavigationController *naviC = [[UINavigationController alloc] initWithRootViewController:mainVC];
self.window.rootViewController = naviC;
[naviC release];
[mainVC release];
return YES;
}

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor magentaColor];
self.title = @"江诗丹顿";
self.navigationItem.title = @"百达翡丽";
self.navigationController.navigationBar.translucent = NO;
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息",@"通话",@"邮箱"]];
seg.frame = CGRectMake(0, 0, 0, 30);
self.navigationItem.titleView = seg;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(leftButtonAction:)];
UIButton *buttonRight = [UIButton buttonWithType:UIButtonTypeCustom];
buttonRight.frame = CGRectMake(0, 0, 40, 40);
[buttonRight setImage:[UIImage imageNamed:@"iconfont-tianchengzuo.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonRight];
self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(90, 60, 200, 40)];
self.myTextField.backgroundColor = [UIColor lightGrayColor];
self.myTextField.layer.cornerRadius = 5;
self.myTextField.layer.borderWidth = 1;
[self.view addSubview:self.myTextField];
[self.myTextField release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(140, 100, 100, 40);
[button setTitle:@"下一页" forState:UIControlStateNormal];
button.layer.cornerRadius = 3;
button.layer.borderWidth = 1;
[self.view addSubview:button];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)rightButtonAction:(UIBarButtonItem *)item
{
}
- (void)leftButtonAction:(UIBarButtonItem *)item
{
}
- (void)click:(UIButton *)button
{
SecondViewController *secVC = [[SecondViewController alloc] init];
secVC.str = self.myTextField.text;
secVC.arr = @[@"杨林",@"刘山山"];
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
}
@interface SecondViewController : UIViewController
@property(nonatomic, assign)NSInteger number;
@property(nonatomic, copy)NSString *str;
@property(nonatomic, retain)NSArray *arr;
@end
- (void)viewDidLoad {
[super viewDidLoad]
self.view.backgroundColor = [UIColor redColor]
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]
button.frame = CGRectMake(140, 100, 100, 40)
[button setTitle:@"下一页" forState:UIControlStateNormal]
button.layer.cornerRadius = 3
button.layer.borderWidth = 1
[self.view addSubview:button]
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]
NSLog(@"%ld", self.number)
self.label = [[UILabel alloc] initWithFrame:CGRectMake(90, 150, 200, 50)]
self.label.backgroundColor = [UIColor brownColor]
self.label.layer.cornerRadius = 5
self.label.layer.borderWidth = 1
[self.view addSubview:self.label]
[self.label release]
self.label.text = self.str
NSLog(@"%@", self.arr)
}
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<SecondViewControllerDelegate>
@property(nonatomic, retain)UIButton *button;
@property(nonatomic, retain)UILabel *label;
@end
@implementation MainViewController
- (void)dealloc
{
[_button release];
[_label release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
self.navigationController.navigationBar.translucent = NO;
self.title = @"劳力士";
self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor];
self.button = [UIButton buttonWithType:UIButtonTypeSystem];
self.button.frame = CGRectMake(140, 100, 100, 40);
self.button.backgroundColor = [UIColor blueColor];
[self.button setTitle:@"下一页" forState:UIControlStateNormal];
self.button.layer.borderWidth = 1;
self.button.layer.cornerRadius = 5;
[self.view addSubview:self.button];
[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(140, 200, 100, 40)];
self.label.backgroundColor = [UIColor cyanColor];
self.label.layer.borderWidth = 1;
self.label.layer.cornerRadius = 3;
[self.view addSubview:self.label];
[self.label release];
}
- (void)click:(UIButton *)button
{
SecondViewController *secVC = [[SecondViewController alloc] init];
secVC.delegate = self;
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
}
- (void)changeValue:(NSString *)value
{
self.label.text = value;
NSLog(@"%@", value);
}
#import <UIKit/UIKit.h>
@protocol SecondViewControllerDelegate <NSObject>
- (void)changeValue:(NSString *)value;
@end
@interface SecondViewController : UIViewController
@property(nonatomic, assign)id<SecondViewControllerDelegate>delegate;
@end
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor];
self.button = [UIButton buttonWithType:UIButtonTypeSystem];
self.button.frame = CGRectMake(140, 100, 100, 40);
self.button.backgroundColor = [UIColor purpleColor];
[self.button setTitle:@"返回" forState:UIControlStateNormal];
self.button.layer.borderWidth = 1;
self.button.layer.cornerRadius = 5;
[self.view addSubview:self.button];
[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(140, 200, 100, 40)];
self.textField.backgroundColor = [UIColor magentaColor];
self.textField.layer.borderWidth = 1;
self.textField.layer.cornerRadius = 5;
[self.view addSubview:self.textField];
[self.textField release];
}
- (void)click:(UIButton *)button
{
[self.delegate changeValue:self.textField.text];
[self.navigationController popViewControllerAnimated:YES];
}