实现两个界面之间内容的传递

//
//  MainViewController.m
//  UI08_TableView界面传值
//
//  Created by dllo on 15/8/7.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate,SecondViewControllerDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)UIImageView *imageView;
@end@implementation MainViewController
-(void)dealloc
{[_arr release];[_imageView release];[_tableView release];[super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil];}return self;
}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.navigationController.navigationBar.translucent=NO;self.navigationItem.title=@"表视图";self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];self.tableView.backgroundColor=[UIColor yellowColor];[self.view addSubview:self.tableView];[self.tableView release];self.tableView.rowHeight=50;self.tableView.dataSource=self;self.tableView.delegate=self;self.imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h1.jpeg"]];self.imageView.frame=CGRectMake(0, -200, self.view.frame.size.width, 200);//给tableview加入头视图//宽是tableview的宽度
//    self.tableView.tableHeaderView=self.imageView;[self.tableView addSubview:self.imageView];self.tableView.contentInset=UIEdgeInsetsMake(200, 0, 0, 0);}
#pragma mark tableview的delegate已经签订好scrollerView的协议,仅仅要设置代理人,就能够使用scrollerview的协议方法
//仅仅要滑动就会触发
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{//获取偏移量CGFloat y=scrollView.contentOffset.y;NSLog(@"%g",y);if (y<0) {self.imageView.frame=CGRectMake(0, y, self.view.frame.size.width, -y);}
}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return self.arr.count;
}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{static NSString *reuse=@"reuse";UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse];if (!cell) {cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
}cell.textLabel.text=self.arr[indexPath.row];cell.detailTextLabel.text=[NSString stringWithFormat:@"%ld",indexPath.section];cell.imageView.image=[UIImage imageNamed:@"天平.png"];return cell;}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{return @"水浒";
}- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{return self.arr;
}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return 1;
}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{SecondViewController *secVC=[[SecondViewController alloc] init];secVC.name= self.arr[indexPath.row];[self.navigationController pushViewController:secVC animated:YES];[secVC release];//secVC.delegate=self;}-(void)changeValue:(NSString *)value
{//属性的数组,相当于数据源,把传过来的值加入到数组中[self.arr addObject:value];//对数据进行刷新[self.tableView reloadData];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}/*
#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller.
}
*/@end
//
//  SecondViewController.h
//  UI08_TableView界面传值
//
//  Created by dllo on 15/8/7.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//#import <UIKit/UIKit.h>
@protocol SecondViewControllerDelegate <NSObject>//协议方法
-(void)changeValue:(NSString *)value;@end
@interface SecondViewController : UIViewController
@property(nonatomic,copy)NSString *name;@property(nonatomic,assign)id<SecondViewControllerDelegate>delegate;@end
//
//  SecondViewController.m
//  UI08_TableView界面传值
//
//  Created by dllo on 15/8/7.
//  Copyright (c) 2015年 zhozhicheng. All rights reserved.
//#import "SecondViewController.h"@interface SecondViewController ()
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,retain)UITextField *textfield;
@property(nonatomic,retain)UIButton *button;@end@implementation SecondViewController
-(void)dealloc
{[_label release];[_textfield release];[_button release];[_name release];[super dealloc];
}
- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.view.backgroundColor=[UIColor cyanColor];self.label=[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 150, 40)];self.label.backgroundColor=[UIColor redColor];self.label.layer.borderWidth=1;self.label.layer.cornerRadius=10;[self.view addSubview:self.label];//赋值self.label.text=self.name;[self.label release];self.textfield=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 40)];self.textfield.layer.borderWidth=1;self.textfield.layer.cornerRadius=10;[self.view addSubview:self.textfield];[self.textfield release];self.button=[UIButton buttonWithType:UIButtonTypeSystem];self.button.frame=CGRectMake(200, 300, 150, 30);[self.button setTitle:@"返回" forState:UIControlStateNormal];[self.view addSubview:self.button];self.button.layer.borderWidth=1;self.button.layer.cornerRadius=5;[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];}
-(void)click:(UIButton *)button
{[self.delegate changeValue:self.textfield.text];[self.navigationController popToRootViewControllerAnimated:YES];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}/*
#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller.
}
*/@end

iOS UI08_TableView界面传值相关推荐

  1. iOS之界面传值(通知,属性,协议,NSUserDefaults,KVC)

    通知传值 通知是在跳转控制器之间常用的传值代理方式.NSNotificationCenter提供了一种解耦的方式,就是任何对象都可以发送通知到中心,同时任何对象可以监听中心的通知. 发送通知(传值页面 ...

  2. iOS 代理反向传值

    iOS 代理反向传值 在上篇博客 iOS代理协议 中,侧重解析了委托代理协议的概念等,本文将侧重于它们在开发中的应用. 假如我们有一个需求如下:界面A上面有一个button.一个label.从界面A跳 ...

  3. fir.im Weekly - iOS 保持界面流畅的技巧

    2019独角兽企业重金招聘Python工程师标准>>> 生命不息,coding 不止.本期 fir.im Weekly 收集了微博上的热转资源,包含 Android.iOS 开发工具 ...

  4. ​iOS的界面触摸事件处理机制,然后用一个实例来说明下应用场景.

    2019独角兽企业重金招聘Python工程师标准>>> 主要是记录下iOS的界面触摸事件处理机制,然后用一个实例来说明下应用场景. 一.处理机制 界面响应消息机制分两块,(1)首先在 ...

  5. Unity3D 游戏引擎之IOS高级界面发送消息与Unity3D消息的接收(九)

    Unity3D 游戏引擎之IOS高级界面发送消息与Unity3D消息的接收 雨松MOMO原创文章如转载,请注明:转载自雨松MOMO的博客原文地址:http://blog.csdn.net/xys289 ...

  6. fir.im Weekly - iOS 保持界面流畅的技巧 1

    生命不息,coding 不止.本期 fir.im Weekly 收集了微博上的热转资源,包含 Android.iOS 开发工具.源码分享,产品 UI 设计的好文章,还有一些程序员成长的 Tips,希望 ...

  7. ios打开html页面关闭当前页面跳转,【已解决】怎么从iOS原生界面跳转回到html页面呢...

    我通过这个代码,跳转到iOS原生界面. // NewViewController为应用内创建的原生的ViewController类名,所调用页面的内容需要在原生代码中完成 var newVCobj = ...

  8. Unity 实现跳转ios 设置界面

    Unity 实现跳转ios 设置界面 一.功能需求 iOS网络设置检查,如果没有网络可能是用户选择关闭了 网络链接,ios可以从游戏内直接跳转到设置网络开关. 二.网络检测 直接上代码 public ...

  9. IOS欢迎界面Launch Screen动态加载广告

    IOS欢迎界面Launch Screen动态加载广告,ioslaunch 当我们打开一款应用程序的时候,首先映入眼帘的往往并不是程序的主界面,而是经过精心设计的欢迎界面,这个界面通常会停留几秒钟,然后 ...

  10. Unity3D 游戏引擎之Unity3D回馈IOS高级界面消息 (十)

    Unity3D 游戏引擎之Unity3D回馈IOS高级界面消息 雨松MOMO原创文章如转载,请注明:转载至我的独立域名博客雨松MOMO程序研究院,原文地址:http://www.xuanyusong. ...

最新文章

  1. this.counter$ = store.select(fromExample.getCounterCounter)之后马上subscribe
  2. Java EE体系概述
  3. Hbase常用基础命令
  4. java token身份认证_java – 基于Spring Security Token的身份验证
  5. 使用ApplicationContext类来完全封装闪屏功能
  6. android图片管理实例,Android图片处理实例介绍(图)
  7. 河北省第三届研究生数学建模B题(二等)交通检测器数据质量控制及预测
  8. 孪生网络pytoch实现,以resnet为特征提取网络
  9. 计算机信息安全认识实习报告
  10. 企业管理系统可视化权限功能设计
  11. android截屏图片大小,Android截屏及图片解析
  12. 好用的三维绘图软件CREO绘制椭圆
  13. 程序员的终极幻想(三):做一只小小的蜗牛
  14. mysql不小心删除root恢复
  15. 8.21. Pseudo-Types
  16. 桌面运维之CMD命令
  17. [技术讨论]从ERP免费开始到做人做事的讨论
  18. (二)使用数组长度实现ADT bag(java)
  19. 这段温暖的路程谁能丈量
  20. C#写Windows Service(windows服务程序)

热门文章

  1. 将string转换为char*
  2. win10 搭建php服务器搭建,Win10平台下安装并配置php
  3. python快速编程入门课本中的名片管理器_Python-名片管理器
  4. ⌊N/1⌋,⌊N/2⌋,...⌊N/N⌋的值的集合的分析
  5. java infinity 处理_Java:如何执行向-Infinity而不是0的整数除法?
  6. 能力提升综合题单 Part 8.9.1 最大流
  7. mycat管理mysql_Mycat用户和权限控制管理
  8. mysql命令行操作语句_MySQL常用命令行操作语句
  9. java 解析 svg_如何解析Java / Android中的SVG?
  10. mysql 伪哈希_MySQL技巧--伪哈希索引