最后效果图:

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

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

tableViewCellStyle

tableView数据源

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

iOS_11_tableViewCell使用alertView变更数据的更多相关文章

  1. [ios]利用alertView 插入数据都数据库。笔记

    利用alertView 插入数据都数据库 -(void)addItemToList { UIAlertView *alter=[[UIAlertViewalloc]initWithTitle:@&qu ...

  2. SQL Server 变更数据捕获(CDC)监控表数据

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现过程(Realization) 补充说明(Addon) 参考文献(References) ...

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

    标签:SQL SERVER/MSSQL SERVER/数据库/DBA/字段/对象更改 概述 变更数据捕获用于捕获应用到 SQL Server 表中的插入.更新和删除活动,并以易于使用的关系格式提供这些 ...

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

    概述 1.变更数据捕获(CDC)        每一次的数据操作都会记录下来 2.更改跟踪       只会记录最新一条记录   以上两种的区别:         http://blog.csdn.n ...

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

    来源:http://www.cnblogs.com/downmoon/archive/2012/04/10/2439462.html  本文主要介绍SQL Server中记录数据变更的四个方法:触发器 ...

  6. CDC变更数据捕获

    CDC变更数据捕获 (2013-03-20 15:25:52)   分类: SQL SQL Server中记录数据变更的四个方法:触发器.Output子句.变更数据捕获(Change Data Cap ...

  7. SqlServer 2014该日志未截断,因为其开始处的记录是挂起的复制操作或变更数据捕获

    环境:AlwaysOn集群 操作系统:Windows Server 2008 R2 数据库: SQL Server 2014 错误提示:“该日志未截断,因为其开始处的记录是挂起的复制操作或变更数据捕获 ...

  8. mysql变更数据的捕获和入库

    问题:涉及状态的信息,mysql中是update的,缺少中间状态的记录.数据分析中需要这部分数据. 思路:后端服务通过监控某张表的某个字段,根据mysql的binlog文件,还原数据,发送到kafka ...

  9. Cocos2d-x数据持久-变更数据

    当数据变化,参与SQL报表insert.update和delete声明.这项3个月SQL语句可以带参数. 详细过程的数据,例如,下面的变化看出.(1) 采用sqlite3_open开放式数据库功能.( ...

随机推荐

  1. WOJ 1055

    #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char s[6]={0} ...

  2. Rapha&#235;l 中文帮助文档(API)

    http://html5css3webapp.com/raphaelApi.htm

  3. JavaEE session机制

    JavaEE session机制 Http协议: 在讲session之前,必须说下Http协议,HTTP是一个client和server端请求和应答的标准(TCP).由HTTPclient发起一个请求 ...

  4. 使用和制作patch文件

    使用和制作patch文件 发表时间: 2007-2-13 20:57    作者: superuser    来源: 迷茫人 字体: 小 中 大 | 打印 原文http://www.linuxsir. ...

  5. EXPORT_SYMBOL解析

    一般我们编写C程序时,要调用某个文件中的函数,需要在本文件中包含声明有被调用函数的头文件,然后编译连接后,方能找到调用函数.对于模块依赖的情况,不能简单的使用上面的方法,内核提供了一个机制,就是EXP ...

  6. configure: error: zlib not installed

    export LDFLAGS="-L/usr/local/zlib/lib" export CPPFLAGS="-I/usr/local/zlib/include&quo ...

  7. 重构后的ConditionHelper

    两三个月前曾写过<重构ConditionHelper>的随笔,但不知是因为写得不够好还是没有什么新意,我发表至博客园首页时被屏蔽了,本着好的知识应该分享给更多人,加之新项目已交付用户使用所 ...

  8. C# 使用Tuple传递多个参数

    Tuple是基于.NET Framework 4.0 及以上版本才有的.微软称它为元组,如果有三个参数那就是三元组.如 Tuple(T1, T2, T3) Tuple的命名空间在 System 很短吧 ...

  9. 【android自己定义控件】自己定义View属性

    1.自己定义View的属性 2.在View的构造方法中获得我们自己定义的属性 3.重写onMesure 4.重写onDraw 3这个步骤不是必须,当然了大部分情况下还是须要重写的. 1.自己定义Vie ...

  10. 阿里云server(ECS)优惠券领取

    CoderMan的博客也是放置在阿里云的ECS上.速度绝对是刚刚的,大家打开的速度肯定不会慢. 有些同志们至今可能还在用虚拟主机吧,其实阿里云server真心不贵,有俩种计费方式:各自是按月计费和按流 ...