//
// 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 {
[super viewDidLoad];
//button,点击方法turntoB,传给B视图的button用
UIButton*button=[[UIButton alloc]initWithFrame:CGRectMake(111, 111, 111, 111)];
button.backgroundColor=[UIColor redColor];
[button addTarget:self action:@selector(turntoB) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: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 {
[super viewDidLoad];
//B的button,方法printB,
UIButton*button=[[UIButton alloc]initWithFrame:CGRectMake(111, 111, 111, 111)];
button.backgroundColor=[UIColor redColor];
[button addTarget:self action:@selector(printB) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
//printB调用A视图的turntoB的方法,,,,,关键
-(void)printB
{
AViewController*view=[[AViewController alloc]init];
[view turntoB];
}
@end

4855

被折叠的 条评论
为什么被折叠?



