本文只要实现运用(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. JavaScript基础插曲—元素样式,正则表达式,全局模式,提取数组

    JavaScript基础学习 学习js的基础很重要,可以让自己有更多的技能.我相信这个以后就会用到. Eg:点击选择框,在div中显示出选择的数量 window.onload = function() ...

  2. HTML5使用Div标签来实现表格

    当支持HTML5时,我们可以使用样式把DIV实现一个表格table. 关键样式语法:display: table,display: table-row,display: table-cell 下面例子 ...

  3. 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览

    在博客园很多文章里面,曾经有一些介绍Office文档预览查看操作的,有些通过转为PDF进行查看,有些通过把它转换为Flash进行查看,但是过程都是曲线救国,真正能够简洁方便的实现Office文档的预览 ...

  4. 【C#】分享基于Win32 API的服务操作类(解决ManagedInstallerClass.InstallHelper不能带参数安装的问题)

    注:这里的服务是指Windows 服务. ------------------201508250915更新------------------ 刚刚得知TransactedInstaller类是支持带 ...

  5. csharp: DBNull and DateTime

    /// <summary> /// /// </summary> /// <param name="dateTime"></param&g ...

  6. SSH实例(5)

    在src中新建struts.xml文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  7. 实现在Android 进程和线程

    进程和线程 如果某个应用程序组件是第一次被启动,且这时应用程序也没有其他组件在运行,则Android系统会为应用程序创建一个包含单个线程的linux进程.默认情况下,同一个应用程序的所有组件都运行在同 ...

  8. NoSQL入门概述

    入门概述 1 NoSQL是什么? NoSQL(NoSQL = Not Only SQL ),意即"不仅仅是SQL",泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关 ...

  9. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  10. IT职业思考 谈谈IT外包公司

    个人能力强才是王道 1. 为什么像BAT.HP.IBM.华为这些大公司还需要外包,他们已经有那么多的技术人员 一个公司,如果没有那么多项目,光养这些技术人员,实际的经营成本确实不低,但是这些技术人员又 ...