1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #import "RootViewController.h" #import "SecondViewController.h" @interface RootViewController ()<SecondViewControllerDelegate>
@end @implementation RootViewController
- (void)viewDidLoad { [super viewDidLoad];
[self createButton]; } -(void)createButton{ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(100, 100, 100, 100); button.backgroundColor = [UIColor lightGrayColor]; [button setTitle:@"下一页" forState:UIControlStateNormal]; [button addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)onClick{ SecondViewController *secondVc = [[SecondViewController alloc]init]; secondVc.delegate = self; [self.navigationController pushViewController:secondVc animated:YES]; }
-(void)changeColor:(UIColor *)color{ [self.view setBackgroundColor:color]; }
@end
|