本文只要实现运用(UITableView)表格实现页面的传值,同时运用了代理(委托)传值。

目录文件列表如下:

AddressBookViewController.h

#import <UIKit/UIKit.h>
#import "ContentViewController.h"
@interface AddressBookViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,postValueDelegate> @end

AddressBookViewController.m

#import "AddressBookViewController.h"

@interface AddressBookViewController ()

@property(strong,nonatomic) UITableView *adderbookview;
@property(strong,nonatomic) NSMutableArray *person;
@property(strong,nonatomic) NSString *str; // 定义一个全局变量来接收行数
@property(assign,nonatomic)int number; @end @implementation AddressBookViewController - (void)viewDidLoad {
// 设置导航栏名称
self.view.backgroundColor=[UIColor colorWithRed:0.344 green:0.976 blue:1.000 alpha:1.000];
self.title=@"通讯录"; // 设置导航栏右边按钮
UIBarButtonItem *nextItem=[[UIBarButtonItem alloc] initWithTitle:@"next" style: UIBarButtonItemStylePlain target:self action:@selector(nextPage)];
self.navigationItem.rightBarButtonItem=nextItem; self.person=[NSMutableArray array];
for (int i=; i<; i++) {
[self.person addObject:[NSString stringWithFormat:@"第%d个联系人",i]];
}
// 初始化 指定样式
self.adderbookview=[[UITableView alloc] initWithFrame:self.view.frame style:];
// 指定代理
self.adderbookview.delegate=self;
self.adderbookview.dataSource=self;
[self.view addSubview:self.adderbookview
]; [self.adderbookview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; self.adderbookview.separatorColor=[UIColor colorWithRed:1.000 green:0.739 blue:0.353 alpha:1.000]; }
#pragma mark - 跳转下一页的方法
-(void)nextPage
{
ContentViewController *contentV=[[ContentViewController alloc] init];
contentV.str=self.str;
[self.navigationController pushViewController:contentV animated:YES];
} #pragma mark - 代理方法 显示选中行的单元格信息
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",self.person[indexPath.row]); self.str=self.person[indexPath.row];
ContentViewController *contentV=[[ContentViewController alloc] init];
contentV.str=self.str;
contentV.delegate=self;
self.number=(int)indexPath.row; [self.navigationController pushViewController:contentV animated:YES];
} #pragma mark - 设置显示分区数量
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} #pragma mark - 数据源 每个分区对应的函数设置
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.person.count;
} #pragma mark - 数据源 每个单元格的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentity=@"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentity forIndexPath:indexPath];
cell.textLabel.text=self.person[indexPath.row]; return cell;
} #pragma mark - 实现代理的方法
-(void)postValue:(NSString *)str
{
[self.person replaceObjectAtIndex:self.number withObject:str];
[self.adderbookview reloadData];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

ContentViewController.h

#import <UIKit/UIKit.h>

@protocol postValueDelegate <NSObject>

-(void)postValue:(NSString *) str;

@end

@interface ContentViewController : UIViewController<UITextFieldDelegate>

@property(strong,nonatomic) UITextField *textInfo;
@property(strong,nonatomic) NSString *str;
@property(strong,nonatomic) id<postValueDelegate> delegate; @end

ContentViewController.m

#import "ContentViewController.h"

@interface ContentViewController ()

@end

@implementation ContentViewController

- (void)viewDidLoad {
[super viewDidLoad];
// 设置导航栏名称及整个背景的颜色
self.view.backgroundColor=[UIColor colorWithRed:1.000 green:0.955 blue:0.563 alpha:1.000];
self.title=@"详情"; // 设置导航栏左边的按钮
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"back" style: target:self action:@selector(backPage)];
// 添加输入框 UITextField
self.textInfo=[[UITextField alloc] initWithFrame:CGRectMake(, , , )];
self.textInfo.borderStyle=;
self.textInfo.text=self.str;
self.textInfo.delegate=self;
[self.view addSubview:self.textInfo]; } #pragma mark - 返回上一页的方法
-(void)backPage
{
[self.navigationController popToRootViewControllerAnimated:YES];
} #pragma mark - 点击空白处隐藏键盘的方法
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.textInfo resignFirstResponder];
} #pragma mark - 点击 return 返回的方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
} if (self.delegate) {
[self.delegate postValue:self.textInfo.text];
}
[self.navigationController popToRootViewControllerAnimated:YES]; return YES;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

AppDelegate.h

#import <UIKit/UIKit.h>
#import "AddressBookViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window; @end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AddressBookViewController *AddressBook=[[AddressBookViewController alloc] init]; UINavigationController *na=[[UINavigationController alloc] initWithRootViewController:AddressBook];
self.window.rootViewController=na;
return YES;
}
.........
@end

注意:

1、在第一页只需要点击UITableView对应的值;

2、在第二页需要按键盘上的 return 健才能传值到第一页。

运行结果:

2016-03-16

iOS--页面跳转(UITableView)的更多相关文章

  1. iOS页面跳转及数据传递

    转: http://blog.csdn.net/wang9834664/article/details/8025571 iOS页面跳转: 第一种 [self.navigationController  ...

  2. iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值

    有时候我们在页面跳转的时候回传递相应的参数,如,你想把在第一个页面的文本框里的内容显示在第二个文本框中,或者你又想把第二个文本框中的内容改变之后到第一个页面的文本框中,所有,这个时候我们就要用到页面跳 ...

  3. ios页面跳转

    reference:http://blog.csdn.net/engandend/article/details/11706323 目前,就我所学到的内容,页面跳转有三种方法 一.直接推到下一个页面 ...

  4. iOS 页面跳转,离开之前pop掉navigationController栈中的页面

    http://blog.csdn.net/worldzhy/article/details/41312713 - (void)viewDidDisappear:(BOOL)animated { //因 ...

  5. ios基础之 透过页面跳转来认识 Strong 与 Weak

    最近在自己做一个小程序,遇到了页面跳转的问题,然后上网一通乱搜,跳转的问题解决了,又有传值的问题.上面两个问题解决了,又发现内存比刚开始时多占用了2M,于是,各种内心纠结,想彻底 搞清楚strong ...

  6. iOS——使用StroryBoard页面跳转及传值

    之前在网上搜iOS的页面跳转大多都是按回以前的那种xib的形式,但鄙人是使用storyboard的.这篇就只介绍利用storyboard进行页面跳转与传值. 新建页面 iOS的程序也是使用了MVC的思 ...

  7. phonegap + 推送 + 页面跳转 (ios)

    os如果没有页面跳转的需求的话就使用极光推送,如果有页面跳转如果用了极光推送就只有用oc去写,但是我不会oc,所以智能放弃极光选用ios自己的apns来实现 新建项目跟安卓创建项目差不多,新建完成后就 ...

  8. ios&h5混合开发项目仿app页面跳转优化

    前言:本人原本是ios开发工程师,但由于现今H5的兴起,行内刮起了一阵混合开发的风气,趁着这股劲,我也学了前端开发,不说研究的多深,但也能胜任日常的开发工作.长话短说,现今的混合开发应该还处于摸索阶段 ...

  9. iOS使用StroryBoard页面跳转及传值

    之前在网上iOS的页面跳转大多都是按回以前的那种xib的形式,但鄙人是使用storyboard的.这篇就只介绍利用storyboard进行页面跳转与传值. 新建页面 iOS的程序也是使用了MVC的思想 ...

  10. IOS 页面间跳转

    常用的就两种 一种通过导航,一种直接跳 第一种 直接跳转 思路大致就是new一个目的页面,然后设置下页面跳转动画 中间还可以做点目的页面的数据初始化: ValueInputView *valueVie ...

随机推荐

  1. linux中不小心将rpm命令卸载了,怎么恢复?

    今天在搭建mysql的集群服务时,安装mysql集群服务前,先卸载原来mysql的软件包,不小心将rpm的命令也给卸载掉了,这下惨了,什么也做不了了.在google了翻了好多个页面,甚至官网也看了,没 ...

  2. 使用Python将HTML转成PDF

    主要使用的是wkhtmltopdf的Python封装--pdfkit 安装 1. Install python-pdfkit: $ pip install pdfkit 2. Install wkht ...

  3. 一对多关系domain Model中设置使用AutoMapper时出错

    在使用AutoMapper时,把数据从VO-PO时显示如下错误,错误提示说在一对多关系中已将集合设置为EntityCollection,那么这个是为什么呢. 看下action中的代码,我们可以发现这是 ...

  4. 关于js性能

    1,声明变量要赋初值2,尽量避免声明全局变量,可以减少与系统的重名3,当编写大量js代码时,难免会遇到命名冲突,这是可以通过模拟命名空间方式     来避免冲突4,尽量避免使用全局变量,搜索全局变量是 ...

  5. R语言介绍

    R语言简介 R语言是一种为统计计算和图形显示而设计的语言环境,是贝尔实验室(Bell Laboratories)的Rick Becker.John Chambers和Allan Wilks开发的S语言 ...

  6. Android调用系统自带的设置界面

    Android有很多系统自带的设置界面,如设置声音,设置网络等. 在开发中可以调用这些系统自带的设置界面. 点击以下列表中的选项,就可以调出相应的系统自带的设置界面. 如点击“无线和网络设置”,可以调 ...

  7. 【转】持久化消息队列之MEMCACHEQ

    G MEMCACHEQ AS MESSAGE QUEUE PHP,消息队列,MEMCACHEQ 使用消息队列(MESSAGE QUEUE)可以把某些耗时的工作推后,然后在后台慢慢地去执行,这样就不会让 ...

  8. Scalaz(26)- Lens: 函数式不可变对象数据操作方式

    scala中的case class是一种特殊的对象:由编译器(compiler)自动生成字段的getter和setter.如下面的例子: case class City(name:String, pr ...

  9. textillate.js 文字动画

    textillate.js是一款强大的文字插件,若配合animate.css.fittext.lettering一起使用,这样做出来的文字特效很完美. 在线实例 实例演示 使用方法 <div i ...

  10. JavaScript实现HTML5烟花特效

    烟花效果如下(请使用支持HTML5的浏览器查看):点击这里查看效果:http://keleyi.com/keleyi/phtml/html5/14.htm 源代码如下: ;}</style> ...