UINavigationController 与其传值

准备工作

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值