溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS頁面跳轉(zhuǎn)及數(shù)據(jù)傳遞的示例分析

發(fā)布時間:2021-07-19 10:36:14 來源:億速云 閱讀:122 作者:小新 欄目:移動開發(fā)

小編給大家分享一下iOS頁面跳轉(zhuǎn)及數(shù)據(jù)傳遞的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

iOS頁面跳轉(zhuǎn):

第一種

[self.navigationController pushViewController:subTableViewController animated:YES];

//描述:通過 NSNavigationBar 進(jìn)行跳轉(zhuǎn)

 [self.navigationController popViewControllerAnimated:YES];

//描述:在子視圖返回到上級視圖

第二種

UIViewController *control = [[UIViewController alloc] init]; [self presentModalViewController:control animated:YES]; [control release];

//描述:通過事件進(jìn)行跳轉(zhuǎn)

[self dismissModalViewControllerAnimated:YES];

//描述:通過事件進(jìn)行返回。

第三種

[self.view.window addSubview:otherview];
[self.view removeFromSuperview]

數(shù)據(jù)傳遞:

1)采用代理模式子viewcontroller設(shè)計 代理協(xié)議,定義協(xié)議接口,父viewcontroller 實現(xiàn)協(xié)議接口,實現(xiàn)子viewcontroller 退出時將相關(guān)數(shù)據(jù)更新到父視圖。
2)采用ios的消息機(jī)制 父viewcontroller注冊消息,子viewcontroller 發(fā)送消息,觸發(fā)父viewcontroller的消息處理。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setData:) name:kNotificationMessage object:nil];

//注冊監(jiān)聽,其中setData用來處理消息

[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationMessage object:self userInfo:infoDict];

//發(fā)送消息

3)采用database做為數(shù)據(jù)中間的存儲媒介,子viewcontroller將狀態(tài)數(shù)據(jù)存入DB,父viewcontroller從DB獲取數(shù)據(jù)更新view.

4)采用ios的NSDefault 存儲

5)通過AppDelegate 中定義全局變量實現(xiàn)中間數(shù)據(jù)的存儲。

以上是“iOS頁面跳轉(zhuǎn)及數(shù)據(jù)傳遞的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

ios
AI