ios--NavigationViewController跳轉、返回傳值

來源:互聯網
上載者:User

標籤:style   io   ar   os   使用   sp   for   on   div   

 

 

使用NavigationViewController進行頁面跳轉時,應該使用pushViewController方法來跳轉至下一頁面,這樣的話,下一頁面同樣在NavigationViewController容器中。

1、跳轉到下一頁面:

 
  1. AloneSetPrizeViewController *setPrize = [[AloneSetPrizeViewController alloc] init];  
  2. // 所要跳轉頁面<span style="font-family: Arial, Helvetica, sans-serif;"> AloneSetPrizeViewController中有個屬性dictionary1是個NSMutableDictionary類型的容 器</span>  
  3. [setPrize.dictionary1 setObject:[self.txtPassWd text] forKey:ALONE_SITEPRIZE_PWD];  
  4. //使用pushViewController跳轉到下一頁面  
  5. [self.navigationController pushViewController:setPrize animated:true];  


2、從當前頁面返回到上一頁面並傳值過去:

 
  1. //此頁面已經存在於self.navigationController.viewControllers中,並且是當前頁面的前一頁面     
  2. AloneSetSiteViewController *setPrizeVC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];  
  3. //初始化其屬性  
  4. setPrizeVC.dictionary = nil;  
  5. //傳遞參數過去  
  6. setPrizeVC.dictionary = [NSMutableDictionary dictionaryWithDictionary:self.dictionary1];  
  7. //使用popToViewController返回並傳值到上一頁面  
  8. [self.navigationController popToViewController:setPrizeVC animated:true];  

返回到上一頁後,上一頁面顯示後要接收參數,並重新整理。注意此時應該在viewDidAppear中進行判斷並接收傳遞的值:

 
  1. -(void)viewDidAppear:(BOOL)animated  
  2. {  
  3.   //判斷並接收返回的參數  
  4.   
  5. }  


3、從當前頁面返回到上一頁面(無需傳值)的方法:

 
    1. //返回到上一介面  
    2. -(IBAction)backOff:(id)sender  
    3. {  
    4.     [self.navigationController popViewControllerAnimated:true];  

ios--NavigationViewController跳轉、返回傳值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.