ios仿淘宝管理收货地址demo
在上篇中出现了复用的问题,然后是用数组承接的,现在我换了一种方法
(1)自定义cell.h
@class MyTableViewCell;
//创建一个代理
@protocol myTabVdelegate <NSObject>
-(void)myTabVClick:(MyTableViewCell *)cell; //因为我要用这个来判定选中的cell
@end
@interface MyTableViewCell : UITableViewCell
//声明一个代码块
@property(strong,nonatomic)void(^btnClick)();
@property(strong,nonatomic)UIButton *btn;
@property(assign,nonatomic)id<myTabVdelegate>delegate;
@end
(2)cell.m的实现
#import "MyTableViewCell.h"
@implementation MyTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_btn = [UIButton buttonWithType:UIButtonTypeCustom];
_btn.frame = CGRectMake(10, 10, 100, 30);
[_btn setTitle:@"test" forState:UIControlStateNormal];
[_btn setBackgroundColor:[UIColor redColor]];
[_btn addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_btn];
}
return self;
}
//按钮事件
-(void)test:(UIButton *)sender
{
[self.delegate myTabVClick:self];
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
(3)VC.m的实现
#import "ViewController.h"
#import "MyTableViewCell.h"
@interface ViewController ()
@property(nonatomic,strong)NSIndexPath *lastPath;
/*注释*/
@property (nonatomic,strong)MyTableViewCell *myCell;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_tableV = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
_tableV.delegate = self;
_tableV.dataSource = self;
[self.view addSubview:_tableV];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify = @"identify";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if (!cell) {
cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
}
//给代码赋值
cell.btnClick = ^(){
NSLog(@"222===%ld",indexPath.row);
};
//给代理赋值
cell.delegate = self;
NSInteger row = [indexPath row];
NSInteger oldRow = [_lastPath row];
if (row == oldRow && _lastPath!=nil)
{
[cell.btn setTitle:@"你好" forState:UIControlStateNormal];
}
else
{
[cell.btn setTitle:@"test" forState:UIControlStateNormal];
}
return cell;
}
//实现代理
-(void)myTabVClick:(MyTableViewCell *)cell
{
NSIndexPath *indexPath = [_tableV indexPathForCell:cell];
NSInteger newRow = [indexPath row];
NSInteger oldRow = (self .lastPath !=nil)?[self .lastPath row]:-1;
if (newRow != oldRow) {
self.myCell = [_tableV cellForRowAtIndexPath:indexPath];
[self.myCell.btn setTitle:@"你好" forState:UIControlStateNormal];
self.myCell = [_tableV cellForRowAtIndexPath:self .lastPath];
[self.myCell.btn setTitle:@"test" forState:UIControlStateNormal];
self .lastPath = indexPath;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
转载于:https://www.cnblogs.com/huiyi-520/p/7501226.html
ios仿淘宝管理收货地址demo相关推荐
- php商城手机端省市显示,jQuery仿手机京东商城收货地址城市选择
jQuery仿手机京东商城收货地址城市选择 js代码 /** * 默认调用 */ !function () { var $target = $('#J_Address'); $target.cityS ...
- 淘集集收货地址在哪改 淘集集添加收货地址方法
淘集集app上购物方便且便宜,所以很多人都在使用.但有些人不知道该如何添加和修改收货地址.所以为大家详细介绍下方法. 淘集集收货地址在哪改 淘集集添加收货地址方法 淘集集收获地址在哪改 1.由于购物下 ...
- dcloud管理收货地址mui
为什么80%的码农都做不了架构师?>>> <!doctype html> <html> <head> <meta charset=&q ...
- 39 Flutter仿京东商城项目 收货地址列表、增加 修改收货地址布局、弹出省市区选择器...
加群452892873 下载对应39课文件,运行方法,建好项目,直接替换lib目录 pubspec.yaml city_pickers: ^0.1.22 AddressAdd.dart import ...
- iOS 仿淘宝,上拉进入详情页面
今天做的主要是一个模仿淘宝,上拉进入商品详情的功能,主要是通过 tableView 与 webView 一起来实现的,当然也可根据自己的需要把 webView 替换成你想要的 // // ViewCo ...
- iOS 仿淘宝实现商品规格图片的放大缩小功能
刚好最近在做个商城项目,甲方爸爸说咱们要求不高,你就照着淘宝来就好,额~~~~ 好吧,咱就不吐槽了,直接开撸吧,惯例先上一下效果图 需求以及思路 我们要实现的功能有如下几个: 图片的全屏查看以及保存 ...
- ios仿淘宝商品详情页面粘贴商品规格弹出模板
- Android仿京东收货地址
Android仿京东三级联动收货地址 1.在本地新建assets目录,存放三级联动json数据,取本地json数据作为数据源 String data = com.miles.zcstc.fingerd ...
- 方便代理下单的EcStore收货地址一键分析插件,同时支持淘宝/京东/一号店
使用EcStore开展分销的网站,代理需要经常代客下单,每个客户收货地址都不同,要选择和填写多个内容才能完成地址输入:省.市.区.详细地址.收货人姓名.手机电话等,非常麻烦,也容易输入错误. 安装Ec ...
最新文章
- 针对《评人工智能如何走向新阶段》一文,继续发布国内外的跟贴留言449-456条如下:
- jQuery中get()和eq()的区别
- python输出一个数的每一位_Python练习实例88 | 读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*。...
- 使用JBoss Fuse和OpenShift进行Cloud Native Camel骑行
- 音视频编解码:NVIDIA Jetson Linux Multimedia API(总结)
- LAMP架构调优(一)——隐藏Apache版本信息
- JavaScript的排序算法
- 系统集成项目管理工程师考试大纲和复习知识点
- nas服务器用户无访问权限,群晖NAS文件权限管理和账户的权限
- 计算机核心论文如何审稿,2021年,审稿快、好中的核心期刊有哪些?
- python中%是什么意思_在python中%是什么意思
- 前端页面加载缓慢的原因和性能优化问题
- 大数据DBA:大数据数据库管理做什么
- 机器学习总结(九):梯度消失(vanishing gradient)与梯度爆炸(exploding gradient)问题
- 无法登录苹果开发者_苹果企业开发者账号怎么申请?失败的原因是什么
- b站如何一次性把up主全部取消关注,让自己去学习
- 那一夜,上海北京被逼到只能说:卧槽
- discus 怎么添加门户功能
- 微信小程序 首行缩进 text 标签 text-indent 不起作用
- 【算法竞赛学习笔记】Link-Cut-Tree基础-超好懂的数据结构
热门文章
- 避免在WHERE条件中,在索引列上进行计算或使用函数,因为这将导致索引不被使用...
- 谈谈自己对REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解
- 企业生产环境下不同业务的linux分区建议
- javascript的族家族史
- 查看服务器Smart Array卡
- SQL Server 2005 Express 版
- 解决Visual Studio 2017隐藏“高级保存选项”命令
- SwiftUI编辑文字和图片
- python turtle库有什么用_Python中turtle库的使用
- js post中服务器500错误信息,node.js - Node Express Post 500(内部服务器错误)jquery-3.4.1.min.js - 堆栈内存溢出...