最后效果图:

Girl.h

//
//  Girl.h
//  11_tableView的使用_红楼梦
//
//  Created by beyond on 14-7-26.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//#import <Foundation/Foundation.h>@interface Girl : NSObject
// UI控件用weak,字符串用copy,其它对象用strong
// 头像图片名
@property(nonatomic,copy)NSString *headImgName;
// 姓名
@property(nonatomic,copy)NSString *name;
// 判词
@property(nonatomic,copy)NSString *verdict;
// 提供一个类方法,即构造函数,返回封装好数据的对象(返回id亦可)
+ (Girl *)girlNamed:(NSString *)name headImgName:(NSString*)headImgName verdict:(NSString *)verdict;
@end

Girl.m

//
//  Girl.m
//  11_tableView的使用_红楼梦
//
//  Created by beyond on 14-7-26.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//#import "Girl.h"@implementation Girl
// 提供一个类方法,即构造函数,返回封装好数据的对象(返回id亦可)
+(Girl *)girlNamed:(NSString *)name headImgName:(NSString *)headImgName verdict:(NSString *)verdict
{Girl *girl = [[Girl alloc]init];girl.name = name;girl.headImgName = headImgName;girl.verdict = verdict;return girl;
}
@end

BeyondViewController.h

//
//  BeyondViewController.h
//  11_tableView的使用_红楼梦
//
//  Created by beyond on 14-7-26.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//#import <UIKit/UIKit.h>@interface BeyondViewController : UIViewController
// 又一次刷新表格时要用到
@property (weak, nonatomic) IBOutlet UITableView *tableView;@end

BeyondViewController.m

//
//  BeyondViewController.m
//  11_tableView的使用_红楼梦
//
//  Created by beyond on 14-7-26.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//#import "BeyondViewController.h"
#import "Girl.h"
@interface BeyondViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
{// 存放假数据NSMutableArray *_array;
}@end@implementation BeyondViewController- (void)viewDidLoad
{[super viewDidLoad];_array = [NSMutableArray array];// 假数据[_array addObject:[Girl girlNamed:@"林黛玉" headImgName:@"0.png" verdict:@"可叹停机德,堪怜咏絮才。

玉带林中挂。金簪雪里埋。"]]; [_array addObject:[Girl girlNamed:@"薛宝钗" headImgName:@"1.png" verdict:@"可叹停机德,堪怜咏絮才。玉带林中挂,金簪雪里埋。"]]; [_array addObject:[Girl girlNamed:@"妙玉" headImgName:@"2.png" verdict:@"欲洁何曾洁,云空未必空。可怜金玉质,终陷淖泥中。

"]]; [_array addObject:[Girl girlNamed:@"史湘云" headImgName:@"3.png" verdict:@"富贵又何为?襁褓之间父母违。

展眼吊斜辉。湘江水逝楚云飞。"]]; [_array addObject:[Girl girlNamed:@"探春" headImgName:@"4.png" verdict:@"才自清明志自高,生于末世运偏消。

清明涕泣江边望,千里东风一梦遥。"]]; [_array addObject:[Girl girlNamed:@"惜春" headImgName:@"5.png" verdict:@"堪破三春景不常,缁衣顿改昔年妆。可怜秀户侯门女,独卧青灯古佛旁。"]]; [_array addObject:[Girl girlNamed:@"王熙凤" headImgName:@"6.png" verdict:@"凡鸟偏从末世来,都知爱慕此生才。

一从二令三人木。哭向金陵事可哀。 "]]; } #pragma mark - tableView的数据源方法 // 数据源方法,特例,重要~ 一共同拥有多少个分组 (默认就是返回1) - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // 单组数据显示,无需分组,故返回 1,(默认就是返回1) return 1; } // 数据源方法,每一组,有多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7; } // 数据源方法,每一组的每一行应该显示怎么的界面(含封装的数据),重点!!! // 每当有一行cell 进入视野范围就会调用 // 必须实现否则,Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"Beyond"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { // 假设池中没取到,则又一次生成一个cell /* cell的4种样式: 1,default 左图右文字 2,subtitle 左图 上文字大 下文字小 3,value 1 左图 左文字大 右文字小 3,value 2 恶心 左文字小 右文字大 */ cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; } // 设置cell中独一无二的内容 Girl *girl = _array[indexPath.row]; cell.imageView.image = [UIImage imageNamed:girl.headImgName]; cell.textLabel.text = girl.name; cell.detailTextLabel.text = girl.verdict; // 设置单元的右边附属 // cell.accessoryType = UITableViewCellAccessoryDetailButton; // cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 返回cell return cell; } #pragma mark - tableView的代理方法 // 代理方法,每一行多高 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 93; } // 代理方法,将要点击某一行的时候调用 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"will select----%d",indexPath.row); return indexPath; } // 代理方法,当点击一行时调用 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"did select----%d",indexPath.row); [tableView deselectRowAtIndexPath:indexPath animated:YES]; Girl *girl = _array[indexPath.row]; // 弹出姓名,以供用户更改 // 设置代理的目的是响应alert的button点击事件 //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:girl.name message:girl.verdict delgate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"other", nil]; UIAlertView *alert = [[UIAlertView alloc]init]; [alert initWithTitle:girl.name message:girl.verdict delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; // alertViewStyle 样式----password // alert.alertViewStyle = UIAlertViewStyleSecureTextInput; // alertViewStyle 样式----一般的文本输入框 alert.alertViewStyle = UIAlertViewStylePlainTextInput; // alertViewStyle 样式----username及password登录框 // alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; // alertViewStyle 样式----标签显示 // alert.alertViewStyle = UIAlertViewStyleDefault; // usernamepassword的情况下有两个文本框 UITextField *textField = [alert textFieldAtIndex:0]; textField.text = girl.name; // 关键代码,通过tag将点击的行号带给alertView的代理方法,还能够通过利用代理即控制器的成员进行 行号 的传递~ textField.tag = indexPath.row; // 显示alertView [alert show]; /* 默认情况下,上面的alert是局部变量,在本方法调完的时候,会被释放 可是,[alert show]方法,会有一种机制(比方UIWindow会持有它的引用,使之不被销毁) */ } // 代理方法,当取消点击一行时调用 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"did deselect row----%d",indexPath.row); } #pragma mark - UIAlertViewDelegate的代理方法 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // 查看点击了alertView里面的哪一个button,取消button是 0 NSLog(@"alertView里面的buttonindex---%d",buttonIndex); if (buttonIndex == 0) { // 0代表取消button return; }else if (buttonIndex == 1){ // 1代表确定button,更新数据源,又一次载入数据 UITextField *textField = [alertView textFieldAtIndex:0]; NSString *newName = [textField text]; // robust推断 if ([newName isEqualToString:@""]) { return; } // 先更新数据源 int row = textField.tag; Girl *girl = _array[row]; girl.name = newName; // 再,所有又一次载入数据 // [_tableView reloadData]; // 最好是,局部刷新数据,通过row生成一个一个indexPath组成数组 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0]; NSArray *indexPaths = @[indexPath]; [_tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft]; } } @end

tableViewCellAccessory

tableViewCellStyle

tableView数据源

版权声明:本文博客原创文章,博客,未经同意,不得转载。

iOS_11_tableViewCell使用alertView变更数据相关推荐

  1. 【SQL Server学习笔记】变更数据捕获(Change Data Capture)

    SQL Server的变更数据捕获(Change Data Capture,CDC),就是异步捕获表数据的修改,只有很少的性能开销,可以持续的更新其他数据源,比如,将联机事务处理数据库中的持续数据变化 ...

  2. SQL Server 2008中新增的变更数据捕获(CDC)和更改跟踪

    SQL Server 2008中新增的变更数据捕获(CDC)和更改跟踪 SQL Server 2008中SQL应用系列--目录索引 本文主要介绍SQL Server中记录数据变更的四个方法:触发器.O ...

  3. SQL Server 变更数据捕获(CDC)

    概述 变更数据捕获用于捕获应用到 SQL Server 表中的插入.更新和删除活动,并以易于使用的关系格式提供这些变更的详细信息.变更数据捕获所使用的更改表中包含镜像所跟踪源表列结构的列,同时还包含了 ...

  4. 【技术实现】java实时同步postgresql变更数据,基于WAL日志

    [技术实现]java基于WAL日志订阅获取postgresql实时变更数据 一.前言 二.WAL日志 三.逻辑解码和逻辑复制 四.准备工作 五.实现步骤(代码示例) 五.总结 一.前言 在以往的工作中 ...

  5. 开启SQLServer数据库的CDC报错:无法更新元数据来指示已对数据库 XXX 启用了变更数据捕获

    开启SQLServer数据库的CDC时,运行报错: 无法更新元数据来指示已对数据库 XXX 启用了变更数据捕获.执行命令 'SetCDCTracked(Value = 1)' 时失败.返回的错误为 1 ...

  6. 变更数据捕获(CDC)

    从广泛意义上说,全球许多企业每天都需要通过频繁的数据批量处理与加载,来定期将数据从一个数据库迁移到另一个数据库(或数据仓库).这类定期批量加载的工作,往往既耗费时间,又会消耗原始系统的大量处理能力.因 ...

  7. 新库上线 | CnOpenData中国工业企业信息变更数据

    CnOpenData中国工业企业信息变更数据 一.数据简介    中国工业企业数据是学术界最常使用也最重要的经济数据之一,其由国家统计局建立,数据来自于样本企业提交给当地统计局的季报和年报汇总形成,覆 ...

  8. 【论文翻译】在不同数据结构中实现变更数据捕获方法以支持实时数据仓库的实验结果

    文章目录 在不同数据结构中实现变更数据捕获方法以支持实时数据仓库的实验结果 1 引言 2 相关工作 3 方法论 3.1 数据来源 3.2 变更数据捕获方法 4 分析和设计 4.1 环境准备 4.2 变 ...

  9. SQL Server 变更数据捕获(CDC)vs 更改跟踪(Chang Tracking)

    一. CDC简介 在2008版本之前,通常使用DML触发器监控对表数据库的变更,但是触发器的维护比较困难,性能也不高.2008推出了新功能 变更数据捕获(Change Data Capture,CDC ...

最新文章

  1. ASP的Server.UrlEncode和Asp.Net的Server.UrlEncode的返回结果不同
  2. POJ3692 最大点权独立集元素个数
  3. VC++ 轻松实现“闪屏” SplashWnd
  4. Android-----Resources
  5. 执行Plugins下的install:install报错:The packaging for this project did not assign a file to the build artif
  6. Javascript Math ceil()、floor()、round()三个函数的区别
  7. PHP学习总结(8)——PHP入门篇之WAMPServer集成环境安装和配置
  8. 前端代码优化的基本原则
  9. [转载] pickle:让python对象序列化
  10. hbase权威指南-客户端API高级特性
  11. laravel学习笔记
  12. 人脸识别 | AI产品经理需要了解的CV通识(二)
  13. mapboxgl绘制3D线教程
  14. 渗透测试常用工具-amap服务枚举
  15. 大文本文件打开工具_信息技术类专业常用工具软件教案1.1
  16. 数显之家快讯:【SHIO世硕心语】2021,写给自己的几段宽心话!
  17. 苹果和虫子c语言编程题,虫子吃苹果:每天10分钟,锻炼少儿编程计算思维
  18. linux 命令:ps 详解
  19. GIS应用技巧之缓冲区分析
  20. iOS开发之支付宝集成

热门文章

  1. 部署SCCM 2012R2之一:了解功能篇
  2. 查看tomcat启动文件都干点啥---server对象
  3. js 图形化工作流设计器
  4. vlc学习计划(5)--VLC程序宏及线程分析
  5. struts 模块化开发学习
  6. 高一计算机组装,高中生计算机组装与维护,呼市新华互联网学校
  7. Nginx反向代理之proxy_pass指令
  8. Nginx server_name通配符匹配配置
  9. what is IOC
  10. 什么时候会触发这个策略呢?