在实际使用中经常有需要点击按钮跳转页面的情况,在OC中的代码实现如下:
首先新建一个button
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 50, 50)]; [button setTitle:@"BACK" forState:UIControlStateNormal];
[self.view addSubview:button];
然后给button注册点击事件
[button addTarget:self action:@selector(buttonBack:) forControlEvents:UIControlEventTouchUpInside];
再把事件中的函数实现(这里跳转的controller记得先import)
- (void)buttonBack:(UIButton *)button {
[self.navigationController popViewControllerAnimated:true];
}
网友评论