iOS_11_tableViewCell使用alertView变更数据

iOS_11_tableViewCell使用alertView变更数据

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

最后效果图:

iOS_11_tableViewCell使用alertView变更数据

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]; ; // alertViewStyle 样式----password // alert.alertViewStyle = UIAlertViewStyleSecureTextInput; // alertViewStyle 样式----一般的文本输入框 alert.alertViewStyle = UIAlertViewStylePlainTextInput; // alertViewStyle 样式----username及password登录框 // alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; // alertViewStyle 样式----标签显示 // alert.alertViewStyle = UIAlertViewStyleDefault; // usernamepassword的情况下有两个文本框 UITextField *textField = ; textField.text = girl.name; // 关键代码,通过tag将点击的行号带给alertView的代理方法,还能够通过利用代理即控制器的成员进行 行号 的传递~ textField.tag = indexPath.row; // 显示alertView ; /* 默认情况下,上面的alert是局部变量,在本方法调完的时候,会被释放 可是,方法,会有一种机制(比方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


iOS_11_tableViewCell使用alertView变更数据


tableViewCellStyle


iOS_11_tableViewCell使用alertView变更数据



tableView数据


iOS_11_tableViewCell使用alertView变更数据

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117667.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 小程序常用的生命周期_小程序组件的生命周期

    小程序常用的生命周期_小程序组件的生命周期小程序的生命周期说白了就是指程序从创建、到开始、暂停、唤起、停止、卸载的过程。我们大概从三个角度看一下小程序的生命周期。(1):应用生命周期(2):页面生命周期(3):应用生命周期影响页面生命周期一:应用生命周期放一张从网上找的图:1:用户首次打开小程序,触发onLaunch(全局只触发一次)。:2:小程序初始化完成后,触发onShow方法,监听小程序显示。3:小程序从前台进入后台,触发onHide方法。:4:小程序从后台进入前台显示,触发onShow方法。5:小程序后台运行一

    2025年7月28日
    3
  • 我的世界服务器作弊指令大全_我的世界服务器称号指令

    我的世界服务器作弊指令大全_我的世界服务器称号指令原标题:我的世界指令代码大全一、我的世界指令代码大全单机指令(部分多人也适用)/gamemode0是生存(极限)模式/gamemode1是创造模式/gamemode2是冒险模式(必须用特定的武器才能消除方块)/gamemode3是生存(极限)模式/give你的名字1371能得到命令方块,在里面输死亡不掉落:/gamerulekeepInventorytrue防爆:/game…

    2022年9月23日
    2
  • 掩模操作

    掩模操作include opencv2 opencv hpp include iostream usingnamespa usingnamespa intmain intargc charargv Matsrc imread D meinv jpg cvNamedWin iostream opencv2

    2025年7月17日
    6
  • volatile关键字到底有什么作用

    volatile关键字到底有什么作用提示:更多优秀博文请移步博主的GitHub仓库:GitHub学习笔记、Gitee学习笔记volatile是Java提供的一种轻量级的同步机制。Java语言包含两种内在的同步机制:同步块(或方法)和volatile变量,相比于synchronized(synchronized通常称为重量级锁),volatile更轻量级,因为它不会引起线程上下文的切换和调度。但是volatile变量的同…

    2022年5月31日
    32
  • linux修改nfs端口,centOS 搭建NFS服务器 配置端口映射使不同网段可访问

    linux修改nfs端口,centOS 搭建NFS服务器 配置端口映射使不同网段可访问1.修改/etc/exports,增加共享文件夹:/home/haishao_deng*(rw,nohide,insecure,no_subtree_check,async,no_root_squash)如果已经安装开启nfs,则只需执行exportfs-rv2.安装NFSsudoyum-yinstallnfs-utilsrpcbindsudochkconfignfson…

    2022年6月27日
    78
  • 带通 带阻滤波器 幅频响应_二阶有源带通滤波器设计

    带通 带阻滤波器 幅频响应_二阶有源带通滤波器设计二阶有源带通滤波器设计1、背景对于微弱的信号的处理方式一般是:放大和滤波,这个过程中就涉及到放大电路的选取、滤波器的选择以及偏置电路的设计。本例以实例的方式讲解并附带参数计算、仿真、实物测试三个环节。 假设需要处理一个20mV的正弦信号,该信号的频率范围是15~35Hz,经过处理后幅值不超过3.3V,且需要经过带通滤波器滤除杂波。2、滤波器定义滤波电路又称为滤波器,是一种选频电路,能够使特定频率范…

    2022年5月2日
    60

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号