iPhone开发--返回UINavigationController的根视图
首先自定义UINavigationBar的左侧返回按钮
[cpp] UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,71.5, 44)];
// UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,200, 44)];
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui.png"] forState:UIControlStateNormal] ;
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui_over.png"] forState:UIControlStateHighlighted] ;
// backBtn.backgroundColor = [UIColor redColor];
[backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside] ;
[backBtn setShowsTouchWhenHighlighted:YES] ;
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backbutton;
[backBtn release] ;
UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,71.5, 44)];
// UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,200, 44)];
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui.png"] forState:UIControlStateNormal] ;
[backBtn setImage:[UIImage imageNamed:@"bt_fanhui_over.png"] forState:UIControlStateHighlighted] ;
// backBtn.backgroundColor = [UIColor redColor];
[backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside] ;
[backBtn setShowsTouchWhenHighlighted:YES] ;
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
self.navigationItem.leftBarButtonItem = backbutton;
[backBtn release] ;
编写点击返回按钮所触发的函数
[cpp] - (void)backButtonClick:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
摘自 zcl369369的专栏
相关新闻>>
- 发表评论
-
- 最新评论 更多>>