iOS页面跳转及数据传递(三种)

2022-11-21,,

本文主要介绍了iOS页面跳转的三种方法及数据传递的方法。具有很好的参考价值。下面跟着小编一起来看下吧

iOS页面跳转:

第一种

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

//描述:通过 NSNavigationBar 进行跳转

 [self.navigationController popViewControllerAnimated:YES];

//描述:在子视图返回到上级视图

第二种

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

//描述:通过事件进行跳转

[self dismissModalViewControllerAnimated:YES];

//描述:通过事件进行返回。

第三种

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

数据传递:

1)采用代理模式子viewcontroller设计 代理协议,定义协议接口,父viewcontroller 实现协议接口,实现子viewcontroller 退出时将相关数据更新到父视图。
2)采用ios的消息机制 父viewcontroller注册消息,子viewcontroller 发送消息,触发父viewcontroller的消息处理。

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

//注册监听,其中setData用来处理消息

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

//发送消息

3)采用database做为数据中间的存储媒介,子viewcontroller将状态数据存入DB,父viewcontroller从DB获取数据更新view.

4)采用ios的NSDefault 存储

5)通过AppDelegate 中定义全局变量实现中间数据的存储。

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持北冥有鱼!

您可能感兴趣的文章:

  • iOS实现APP程序内部打开APP的AppStore页面
  • IOS 应用内显示 AppStore 某个应用的详情
  • iOS中在APP内加入AppStore评分功能的实现方法
  • iOS开发中ViewController的页面跳转和弹出模态
  • iOS应用开发中实现页面跳转的简单方法笔记
  • iOS如何跳转到App Store下载评分页面示例代码

《iOS页面跳转及数据传递(三种).doc》

下载本文的Word格式文档,以方便收藏与打印。