【学习笔记】AB调方法

来源:互联网 发布:电脑数据丢失怎么办 编辑:程序博客网 时间:2024/05/24 05:19

//

//  AViewController.h



#import <UIKit/UIKit.h>

#import "BViewController.h"


@interface AViewController :UIViewController

-(void)turntoB;//方法全局,用来传

@end



//  AViewController.m


#import "AViewController.h"

#import "BViewController.h"


@interface AViewController ()

@end

@implementation AViewController


- (void)viewDidLoad {

    [superviewDidLoad];


//button,点击方法turntoB,传给B视图的button

    UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(111,111, 111, 111)];

    button.backgroundColor=[UIColorredColor];

    [button addTarget:selfaction:@selector(turntoB)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];

}


//方法

-(void)turntoB

{

    NSLog(@"22222222"); 

}


@end



//

//  BViewController.h


#import <UIKit/UIKit.h>

#import "AViewController.h"    //A的方法


@interface BViewController :UIViewController

@end



//

//  BViewController.m


#import "BViewController.h"


@interface BViewController ()

@end

@implementation BViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

//Bbutton,方法printB

    UIButton*button=[[UIButtonalloc]initWithFrame:CGRectMake(111,111, 111, 111)];

    button.backgroundColor=[UIColorredColor];

    [button addTarget:selfaction:@selector(printB)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:button];

 

}


//printB调用A视图的turntoB的方法,,,,,关键

-(void)printB

{

    AViewController*view=[[AViewControlleralloc]init];

    [viewturntoB];  

}




@end



0 0
原创粉丝点击