最终效果图:

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;// 返回cellreturn 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的按钮点击事件//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 样式----密码// alert.alertViewStyle = UIAlertViewStyleSecureTextInput;// alertViewStyle 样式----一般的文本输入框alert.alertViewStyle = UIAlertViewStylePlainTextInput;// alertViewStyle 样式----用户名及密码登录框// alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;// alertViewStyle 样式----标签显示// alert.alertViewStyle = UIAlertViewStyleDefault;// 用户名密码的情况下有两个文本框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里面的哪一个按钮,取消按钮是 0NSLog(@"alertView里面的按钮index---%d",buttonIndex);if (buttonIndex == 0) {// 0代表取消按钮return;}else if (buttonIndex == 1){// 1代表确定按钮,更新数据源,重新加载数据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. mysql并发更新数据,多用户并发修改数据解决方案。

    mysql并发更新数据,多用户并发修改数据解决方案. 在系统中,有一些如余额.资产.积分的数据,是要保证数据一致性的.如,一个人使用两个设备同时进行消费操作,如何保证数据一致性的问题. 我们一起来思考 ...

  2. 【jdbc】兴唐第三十一节课之修改数据和查询数据(使用自己写的DBUtil)

    一.修改数据 方法一 代码实现: public static void opDBByNormal() {DruidDataSource dds = new DruidDataSource(); dds ...

  3. fiddler使用技巧进阶,如何抓包修改数据?——AutoResponder重定向

    " 介绍Fiddler的AutoResponder重定向功能." Fiddler功能十分强大,既能抓取报文,也能构造报文,本文继续介绍fiddler的功能,这次的功能与构造报文相关 ...

  4. pb 修改数据窗口种指定字段位置_如何在PB数据窗口中修改数据---设置数据窗口的更新属性...

    如何在 PB 数据窗口中修改数据 --- 设置数据窗口的更新属性 数据窗口对象非常强大的原因之一就是能够很容易地修改数据库.当用户修 改了数据窗口中的数据,插入了新的数据行或者删除了数据行以后,只要调 ...

  5. 分享:bbed修改数据文件头推进scn与其他数据文件相同

    2019独角兽企业重金招聘Python工程师标准>>> 场景简介: 物理copy表空间数据文件,数据库发生完全检查点,删除该表空间下的数据文件,使该表空间数据文件头的scn与其他数据 ...

  6. mysql所有的编码_MySQL 批量修改数据表编码及字符集

    当需要修改数据库编码和字符集时,通常需要对其下属的所有表及表中所有字段进行修改.以下备注批量修改方案( 以修改为 utf8mb4_bin 为例,注意将 db_name 换为真实的数据库名 ). 1. ...

  7. php pdo 方法,PHP使用PDO修改数据的方法

    PHP使用PDO修改数据的方法 发布时间:2020-06-09 11:31:36 来源:亿速云 阅读:263 作者:Leah 这篇文章给大家分享的是PHP使用PDO修改数据的方法.小编觉得挺实用的,因 ...

  8. Fast RCNN 训练自己数据集 (2修改数据读取接口)

    Fast RCNN 训练自己数据集 (2修改数据读取接口) Fast RCNN训练自己的数据集 (2修改读写接口) 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.co ...

  9. 【RecyclerView】 十二、RecyclerView 数据更新 ( 修改单条数据 | 批量修改数据 )

    文章目录 一.修改单条数据 二.批量修改数据 三.完整代码示例 四.RecyclerView 相关资料 一.修改单条数据 修改单条数据 : 调用 RecyclerView.Adapter 的 void ...

最新文章

  1. OpenCV 【七】————边缘提取算子(图像边缘提取)——canny算法的原理及实现
  2. springboot怎么写上传头像接口?
  3. XAMPP环境下apache无法启动(端口未被占用)的解决方法
  4. 让你受用一辈子的181句话
  5. zookeeper下载地址及常见配置项
  6. Android Studio下载
  7. 字典树 HDU1251
  8. linux+nginx+php+mysql安装及配置
  9. 大数据开发笔记(三):Mapreduce
  10. websocket连接相关的几个问题
  11. 23种设计模式(十八)状态变化之备忘录
  12. 微型计算机控制系统一般结构框图,微型计算机控制系统的组成-精品文档.ppt
  13. C语言三个点“...“符号含义之数组批量赋相同值
  14. angular时间格式化
  15. word2010添加论文引用
  16. 全球与中国的前50家最佳网站
  17. Settings 设置
  18. 几分钟内上线一个网站,这些神器我爱了!
  19. ICC II 4 timing setup(MCMM的设置)
  20. uniapp sl-filter条件筛选组件

热门文章

  1. 华硕P8Z77 双显示器连接方法, 远程桌面双显示器的连接方法
  2. Solana CEO做客吉姆 · 克莱默《Mad Money》谈融资后规划
  3. 可以替代传统T卡的存储芯片 CS品牌SD NAND
  4. LeetCode 力扣 529. 扫雷游戏 minesweeper DFS
  5. 计算机丢失disrupt,词根rupt家族:corrupt,disrupt,interrupt
  6. 机器学习 Hidden Markov Models 2
  7. 央视揭秘:自嘲脸盲的刘强东 这样从农村少年走向成功
  8. 我的创作纪念日-五周年
  9. 【百面机器学习】优化算法
  10. Windows上也可以开发 iOS App了