你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iPhone開發--返回UINavigationController的根視圖

iPhone開發--返回UINavigationController的根視圖

編輯:IOS開發綜合

首先自定義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的專欄

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved