iOS 传值方式一
来源:互联网 发布:大数据具有哪些特征() 编辑:程序博客网 时间:2024/05/05 05:29
iOS的传值方式一:
前往后传值**《》《》《》《》通过属性传值
@interface NewsController : UIViewController 从 NewsController 往后传值#pragma mark 点击cell 传递值 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // QianChuanHouController 是后面接收数据的页面 QianChuanHouController *controll = [[QianChuanHouController alloc]init]; UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:controll]; NewsModel *models = self.dataArray[indexPath.row]; controll.model = models; [self presentViewController:na animated:YES completion:nil]; NSLog(@"%ld", indexPath.row);}
// 这个是 接收页面 @protocol QianChuanZhiDelegate <NSObject>@property (nonatomic, strong)NewsModel *model;// 这样就可以把 数据从前一个页面传给后一个页面
传值方式二:<><><><><><><> 后面往前传 通过代理传值
在后面要传值的页面 设置代理 并且设置方法
在前面要接受值得页面 遵循代理实现代理方法
// 后面往前传 需要用到代理 在 QianChuanHouController 控制器里面设代理 // 声明代理 @protocol QianChuanZhiDelegate <NSObject> //声明代理方法 @optional - (void)ViewController:(NSString *)string;@end@interface QianChuanHouController : UIViewController@property (nonatomic, strong)NewsModel *model;@property (nonatomic, strong)id <QianChuanZhiDelegate>delegate; ```
// 实现代理方法- (void)actionss { // 实现代理方法 [self.delegate ViewController:self.model.name]; [self dismissViewControllerAnimated:YES completion:nil];}
// 在接接收的页面遵循代理并且实现方法@interface NewsController ()<QianChuanZhiDelegate>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ QianChuanHouController *controll = [[QianChuanHouController alloc]init]; controll.delegate = self; UINavigationController *na = [[UINavigationController alloc]initWithRootViewController:controll]; NewsModel *models = self.dataArray[indexPath.row]; controll.model = models; [self presentViewController:na animated:YES completion:nil]; NSLog(@"%ld", indexPath.row);}// 实现代理方法- (void)ViewController:(NSString *)string{ NSLog(@"代理传值 %@", string);}
0 0
- iOS 传值方式一
- iOS 页面传值4种方式(一) 之全局变量
- ios 传值方式
- iOS传值方式
- iOS 各种传值方式
- iOS 各种传值方式
- iOS 各种传值方式
- iOS 各种传值方式
- ios-传值方式总结
- ios -- ViewController(xib)切换方式一
- ios -- ViewController跳转+传值(方式一)
- ios -- ViewController跳转+传值(方式一)
- iOS 多线程编程<一、多线程实现方式>
- 《iOS总结》传值方式-MickyChiang
- iOS 页面间的传值方式
- iOS开发常用传值方式总结
- iOS五种页面传值方式
- iOS六种传值方式之通知传值
- 【rabbitmq】Warning: PID file not written; -detached was passed. ERROR: node with name "rabbit" alread
- 百炼OJ1009
- React Native For Android初探-问题小结
- 时间过滤器[avalon]
- C#异步:实现一个最简单的异步
- iOS 传值方式一
- Elasticsearch lucene搜索引擎实现
- DTD详解
- 用 Webgoat 撬动地球,看安全测试的引路石!
- 统计分析:变异系数
- 如何关闭sentos7和6.5防火墙
- Oracle权限管理
- 在字符串中搜寻短字符串/字符的位置!
- 3.6线程间的通信:字节流与字符流