码迷,mamicode.com
首页 > 其他好文 > 详细

页面传值总结Block

时间:2015-07-12 18:46:47      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

//
//  AppDelegate.m
//  页面传值总结
//
//  Created by qianfeng on 15/6/13.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    ViewController *ctr = [[ViewController alloc]init];
    UINavigationController*nav = [[UINavigationController alloc]initWithRootViewController:ctr];
    self.window.rootViewController = nav;
    
    
    return YES;
}

 

//
//  ViewController.m
//  页面传值总结
//
//  Created by qianfeng on 15/6/13.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "ViewController.h"
#import "DetailVIewController.h"



@interface ViewController ()
{
    UILabel*_label;
    
}
@property(nonatomic,strong)UILabel*label;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    //用于显示第二个界面传过来的数据。
    _label = [[UILabel alloc]initWithFrame:CGRectMake(120, 220, 100, 40)];
    _label.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_label];
    
    
    //创建用于跳转到第二个界面的按钮;
    UIButton*btn = [self createBtnFrame:CGRectMake(120, 300, 100, 40) title:@"跳转" target:self action:@selector(clickBtn:)];
    btn.backgroundColor = [UIColor grayColor];
    [self.view addSubview:btn];
    
    
    
}



-(void)clickBtn:(id)sender
{
    DetailVIewController*ctr = [[DetailVIewController alloc]init];
    __weak ViewController*weakself =self;
    ctr.clockBlock = ^(NSString*title){
        weakself.label.text = title;
        
    };
       [self.navigationController pushViewController:ctr animated:YES];
    
}


-(UIButton*)createBtnFrame:(CGRect)frame title:(NSString*)title target:(id)target action:(SEL)action
{
    UIButton*btn= [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = frame;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

页面传值总结Block

标签:

原文地址:http://www.cnblogs.com/0515offer/p/4641299.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!