ios--NavigationViewController跳轉、返回傳值

來源:互聯網
上載者:User

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

1、跳轉到下一頁面:

AloneSetPrizeViewController *setPrize = [[AloneSetPrizeViewController alloc] init];//所要跳轉頁面AloneSetPrizeViewController中有個屬性dictionary1是個NSMutableDictionary類型的容器[setPrize.dictionary1 setObject:[self.txtPassWd text] forKey:ALONE_SITEPRIZE_PWD];//使用pushViewController跳轉到下一頁面[self.navigationController pushViewController:setPrize animated:true];

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

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

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

-(void)viewDidAppear:(BOOL)animated{  //判斷並接收返回的參數}

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

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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.