今天有些匆忙。

效果图如下:

代码如下:

#import <UIKit/UIKit.h>
#import "FirstViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *first=[[FirstViewController alloc]init];
UINavigationController *navc=[[UINavigationController alloc]initWithRootViewController:first];
self.window.rootViewController=navc;
return YES;
}
#import <UIKit/UIKit.h>
#import "SecondViewController.h" @interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,postValueDelegate> @property(strong,nonatomic)UITableView * tableview; @property(strong,nonatomic)NSMutableArray *array; @property(strong,nonatomic)NSString *st; @end
#import "FirstViewController.h"

@interface FirstViewController ()

@property(assign,nonatomic)int a;

@end

@implementation FirstViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
self.title=@"首页";
UIBarButtonItem *nextItem=[[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(nextpage)];
self.navigationItem.rightBarButtonItem=nextItem; self.array=[NSMutableArray array]; for (int i=1; i<20; i++) {
[self.array addObject:[NSString stringWithFormat:@"你摔了%d跤",i]];
} self.tableview=[[UITableView alloc]initWithFrame:self.view.frame style:1]; self.tableview.separatorColor=[UIColor redColor]; self.tableview.delegate=self; self.tableview.dataSource=self; [self.view addSubview:self.tableview]; [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
} -(void)postvalue:(NSString *)str
{
// self.st=str; [self.array replaceObjectAtIndex:self.a withObject:str]; [self.tableview reloadData]; // NSLog(@"%@",self.st); } #pragma mark 数据源 每个分区显示行数设置
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.array.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.array[indexPath.row]; return cell;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ NSLog(@"%@",self.array[indexPath.row]); self.st=self.array[indexPath.row];
SecondViewController *second=[[SecondViewController alloc]init];
second.str=self.st;
second.delegate=self;
self.a=(int)indexPath.row; NSLog(@"%d",self.a); [self.navigationController pushViewController:second animated:YES];
} -(void)nextpage
{
SecondViewController *second=[[SecondViewController alloc]init]; second.str=self.st; [self.navigationController pushViewController:second animated: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
#import <UIKit/UIKit.h>
//创建协议,声明方法
@protocol postValueDelegate <NSObject> -(void)postvalue:(NSString* )str; @end @interface SecondViewController : UIViewController<UITextFieldDelegate> @property(strong,nonatomic) UITextField * textName; @property(strong,nonatomic) NSString *str; @property(strong,nonatomic) id<postValueDelegate> delegate; @end
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor greenColor];
self.navigationItem.hidesBackButton=YES;
self.title=@"尾页";
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"back" style:2 target:self action:@selector(backpage)]; self.textName=[[UITextField alloc]initWithFrame:CGRectMake(100, 300, 150, 60)]; self.textName.borderStyle=1; self.textName.text=self.str; self.textName.delegate=self; [self.view addSubview:self.textName];
} -(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
} if (self.delegate) {
[self.delegate postvalue:self.textName.text]; } [self.navigationController popToRootViewControllerAnimated:YES]; return YES;
} -(void)backpage
{
if (self.delegate) {
[self.delegate postvalue:self.textName.text];
NSLog(@"%@",self.textName.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

UITableView传值(自己使用)(属性,代理传值)的更多相关文章

  1. iOS 页面间几种传值方式(属性,代理,block,单例,通知)

    第二个视图控制器如何获取第一个视图控制器的部分信息 例如 :第二个界面中的lable显示第一个界面textField中的文本 这就需要用到属性传值.block传值 那么第一个视图控制器如何获的第二个视 ...

  2. iOS传值方式:属性,代理,block,单例,通知

    正向传值均可,反向传值除属性传值不可,其余均可.下面简单介绍: (一)属性传值 第二个界面中的lable显示第一个界面textField中的文本 首先我们建立一个RootViewControllers ...

  3. 四大传值详解:属性传值,单例传值,代理传值,block传值

    一:属性传值 传值情景:从前一个页面向后一个页面传值 a.在后一个页面,根据传值类型和个数,写属性 b.在前一个页面, 为属性赋值 c.在后一个页面, 使用值 例如: 第一个视图: #import & ...

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

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

  5. iOS--页面间的代理传值(属性、代理(委托)、代码块、单例、通知)

    (一)属性传值 (二)代理(委托)传值 代理传值 适用于 反向传值 (从后往前传) 1.1 创建协议 及协议方法 在反向传值的页面(SecondViewController)中 1.2 创建协议类型的 ...

  6. iOS 页面间传值 之 属性传值,代理传值

    手机 APP 运行,不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代理传值. 属性传值:属性传值是最简单,也是最常见的一种传值方式,但 ...

  7. Swift进阶之路(一)——单例模式、属性传值、代理传值、闭包传值

    一.单例模式 单例模式是设计模式中最简单的一种,甚至有些模式大师都不称其为模式,称其为一种实现技巧,因为设计模式讲究对象之间的关系的抽象,而单例模式只有自己一个对象. 关于单例,有三个重要的准则需要牢 ...

  8. OS笔记047代理传值和block传值

    在两个不同的控制器之间传递数据,可以使用代理传值或者block传值. 例子是一个简单通讯录. 主界面如下: 添加联系人界面 查看/编辑联系人界面:默认是查看模式,点击编辑后进入编辑模式 编辑模式 数据 ...

  9. View 与 Controller 之间的delegate(代理)传值

    这个代理传值是经常使用的一种传值方式,下面介绍一种View 和 Controller 之间的代理传值方法. 先建立一个View视图 如 LoginView 是继承于一个UIView 在LoginVie ...

  10. IOS pop使用代理传值

    假如oneViewController页面push到OtherViewController页面,然后你想从OtherViewController页面pop到oneViewController页面的时候 ...

随机推荐

  1. 使用Microsoft Fakes进行单元测试(2)

    接上一篇使用Microsoft Fakes进行单元测试(1) 下面进行Shim的演示. 2.使用Shim替换静态方法 假设我们需要一个工具方法用来格式化当前时间为字符串,因为DateTime.Now一 ...

  2. C#基础02

    学习"传智播客视频基础"做的课堂笔记,您有幸读到,若其中有错误部分,请您务必指明.另外请给出您的宝贵建议,谢谢. **************基础知识************ 1: ...

  3. 使用NuGet打包并发布至ProGet过程 (打包再次详解)【下篇】

    一.前言 上篇[1]主要介绍了利用csproj文件使用NuGet打包至ProGet的过程,并附上了用于在Jenkins上运行的python脚本.本篇的主要内容分为以下几点: 1. Nuspec与Nup ...

  4. WPF学习之绘图和动画

    如今的软件市场,竞争已经进入白热化阶段,功能强.运算快.界面友好.Bug少.价格低都已经成为了必备条件.这还不算完,随着计算机的多媒体功能越来越强,软件的界面是否色彩亮丽.是否能通过动画.3D等效果是 ...

  5. 【UWP】不通过异常判断文件是否存在

    从WP升到WinRT(Win8/WP8.1/UWP)后所有的文件操作都变成StorageFile和StorageFolder的方式,但是微软并没有提供判断文件是否存在的方法通常的做法我们可以通过下面方 ...

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

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

  7. hibernate----component-entity (人-地址-学校)

    package com.ij34.dao; import javax.persistence.*; @Entity @Table(name="school_inf") public ...

  8. 用xutils3.0进行下载

    写的例子比较简单,是用xutils3.0来进行下载项目更新 1.先通过网络请求,判断版本是否要更新 2.若要更新,则弹出一个弹窗,我用的是系统自带的Dialog,将下载的版本号及下载的内容提示展示出来 ...

  9. Maven依赖Scope标签用法

    在一个maven项目中,如果存在编译需要而发布不需要的jar包,可以用scope标签,值设为provided.如下: <dependency>            <groupId ...

  10. 完善ext.grid.panel中的查询功能(紧接上一篇)

    今天的代码主要是实现,Ext.grid.panel中的查询,其实我也是一名extjs新手,开始想的实现方式是另外再创建一个新的grid类来存放查询出的数据(就是有几个分类查询就创建几个grid类),这 ...