UINavigationController 与其传值
2015-08-08 22:05
363 查看
准备工作
导航视图控制器的高度是44, 上面的状态栏的高度是20, 加在一起的默认高度是64.
给导航视图控制器加上标题
背景设置
属性传值
协议传值
MainViewControll *mainAC = [[MainViewControll alloc] init]; UINavigationController *ngaAC = [[UINavigationController alloc] initWithRootViewController:mainAC]; self.window.rootViewController = ngaAC;
导航视图控制器的高度是44, 上面的状态栏的高度是20, 加在一起的默认高度是64.
给导航视图控制器加上标题
self.title = @"何以笙萧默"; 或者: self.navigationItem.title = @"微微一笑很倾城";
背景设置
// 并不是所有的背景都是backgroundColor self.navigationController.navigationBar.barTintColor = [UIColor blackColor]; // 为了防止坐标系被串改,我们把Bar从半通明设置成不透明,这样坐标系的圆点就回自动向下推64. self.navigationController.navigationBar.translucent = NO; // 指定一些视图, 成为titleView UISegmentedControll *seg = [[UISegmentedControl alloc] initWithItems:@[@"信息", @"通话"]]; self.navigationTtem.titleView = seg; // 创建左右两边的按钮 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(liftButtonACtion:)] autorelease]; self.navigationItem.rghtBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"图片名"] style:UIBarButtonItemStylePlain target:self action:@selector(方法名)] autorelease]; 或者: UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom]; rightButton.frame = CGRectMake(0, 0, 40, 40); [rightButton setImage:[UIImage imageNamed:@"照片名"] forState:UIControlStateNormal]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
属性传值
UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(200, 100, 100, 40); button.layer.borderWidth = 1; [button setTitle:@"下一页" forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; self.myTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 40)]; self.myTextField.layer.borderWidth = 1; self.myTextField.layer.cornerRadius = 10; [self.view addSubview:self.myTExtField]; [_myTextField release]; - (void)buttonAction:(UIButton *)button { SecondViewController *secondAC = [[secondViewController alloc] init]; // 模块跳转 secondAC.modalTransitionStyle = UIModalTransitionStyleCoverVertical]; [self presentViewController:secondAC animated:YES completion:^{ }]; // 导航视图控制器跳转 [self.navigationController pushViewController:secondAC animated:YES]; [secondAC release]; secondAC.str = self.myTestField.Text; }
协议传值
// 1. 声明一份协议 @protocol SecondViewControllerDelegate<NSObject> // xieyifangf - (void)changeValue:(NSString *)value; @end @interface SecondViewController : UIViewController // 2. 设置代理人的属性 @property(nonatomic, assign)id<secondViewControllerDelegate>delegade; @end // 协议的触发条件是点击按钮, 所以在这里进行协议传值的第3部 // 3. 设置代理人的协议方法 - (void)buttonAction:(UIButton *)button { [self.navigationController popViewControllerAnimated:YES]; [self.delegate changeValue:self.textfied.text]; } // 4. 签订协议 @interface mainViewController()<SecondViewControllerDelegate> @end // 5. 设置代理人 - (void)buttonAction:(UIButton *)button { SecondViewController *secondAC = [[SecondViewController alloc] init]; [self.navigationController pushViewController:secondAC animated:YES]; secondAC.delegate = self; } // 6. 实现协议方法 - (void)changeValue:(NSString *)value { self.lable.text = value; }
相关文章推荐
- UI05_手势识别器
- iOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果
- UI, 猜数字游戏的实现
- UITableView
- 【Android UI】ViewPage
- leetcode - Unique Paths II
- UIStepper
- UIScrollView 按页面滚动视图 UIPageControl
- POJ2478 Farey Sequence(欧拉函数,打表)
- Pixel Width of the text in a UILabel
- UITableView省市区字典
- UI05_Control(UIStepper加减音量/UIBlurEffect毛玻璃/UISlider滑动/UISegmentedControl小模块)
- [leetcode] Implement Queue using Stacks
- UIButton的一些常用知识点
- [leetcode 234]Implement Queue using Stacks
- UVA 10420 List of Conquests
- UIViewController的生命周期
- UIViewController
- opencv开发之MFC的.SetWindowTextA() + OnTimer(UINT_PTR nIDEvent) +cvNamedWindow 在MFC上显示
- UI中简单的猜数字游戏