如何得到自定义UITableViewCell中的按钮所在的cell的indexPath.row
在自定义UITableViewCell中创建了一个按钮。
两种方法都很好。
-(IBAction):(id)sender
{
NSLog(@"MyRow:%d",[self.table indexPathForCell:((TableViewCell*)[[sender superview]superview])].row); //这个方便一点点,不用设置tag。
NSLog(@"MyRow:%d",((TableViewCell*)[[sender superview]superview]).tag);
//这个需要加载cell时设置tag.不过也很方便。
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//删除cell.contentView中所有内容,避免以下建立新的重复
int i = [[cell.contentView subviews] count] - 1;
for(;i >= 0 ; i--)
{
[[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
}
//添加button
UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
[but setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
[but setFrame:CGRectMake(280, 10, 30, 30)];
[but setAlpha:0.8];
[but addTarget:self action:@selector(del:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:but];
//设置Tag为cell 对应的indexPath row
for(id view in subviews)
{
if([view isKindOfClass:[UIButton class]])
{
[view setTag:[indexPath row]];
//[cell.contentView bringSubviewToFront:view];
}
}
}
//Button事件
-(void)del:(id)sender
{
for(UITableViewCell *cell in visiblecells)
{
if(cell.tag == button.tag)
{
//button.tag就是对应的[indexPath.row
}
如何得到自定义UITableViewCell中的按钮所在的cell的indexPath.row的更多相关文章
- iOS 获取自定义cell上按钮所对应cell的indexPath.row的方法
在UITableView或UICollectionView的自定义cell中创建一button,在点击该按钮时知道该按钮所在的cell在UITableView或UICollectionView中的行数 ...
- 自定义UITableViewCell 的delete按钮
自定义UITableViewCell上的delete按钮 滑动列表行(UITableViewCell)出现删除按钮时,默认是英文“delete”,这份代码片段能够将“delete”变成中文”删除“,甚 ...
- 自定义UISearchDisplayController中搜索到结果的cell的位置
#pragma mark - UISearchBarDelegate//当搜索文本被改变的时候调用 - (void)searchBar:(UISearchBar *)searchBar textDid ...
- cell中button怎么得到对应cell的indexpath 以及关于UITableViewCellContentView的问题
============================================================ 博文原创,转载请声明出处 电子咖啡-专注于移动互联网 ============ ...
- 自定义uitableviewcell通过加上滑动手势进行删除对应的行。PS:用代理来实现
#import <UIKit/UIKit.h> @class ZSDCustomCell; //协议 @protocol ZSDCustomCellDelegate <NSObjec ...
- ios 获取button所在的cell对象, 注意:ios7 =< System Version < ios8 获取cell对象的差别
ios7 =< System Version< ios8 : ios7 =< System Version < ios8 下 button.superview.supervi ...
- 点击Cell中的按钮时,如何取所在的Cell
4.点击Cell中的按钮时,如何取所在的Cell:-(void)OnTouchBtnInCell:(UIButton *)Btu{CGPoint point = btn.center;point = ...
- iOS中自定义UITableViewCell的用法
1.先创建一个View继承 UITableViewCell并使用xib快速建立模型. #import <UIKit/UIKit.h> #import "Score.h" ...
- 点击tablecell中的一个按钮,确定cell所在的行
- (void) del:(UIButton *) button { NSLog(@"%s",__FUNCTION__); UITableViewCell * cell = (UI ...
随机推荐
- AWS-CDH5.5安装 CM配置节点
在CM节点上进行安装时出现错误: ================================================================================ Pa ...
- wx jssdk
public static Dictionary<string,string> jsstr(string url) { //noncestr ); //timestamp TimeSpan ...
- 作业七:团队项目——Alpha版本冲刺阶段005
今日进展:编写代码. 今日安排:完成开始部分代码.
- [收藏]谷歌htm/css规范
通用样式规范 协议 省略图片.样式.脚本以及其他媒体文件 URL 的协议部分(http:,https:),除非文件在两种协议下都不可用.这种方案称为 protocol-relative URL,好处是 ...
- 近期编程问题——read:resource temporarily unavailable
EAGAIN错误 出现问题:read:resource temporarily unavailable 原因:这种错误一般出现宰非阻塞的socket编程中,资源暂时不可用. 我的解决方法:囧,后来改成 ...
- ov5648摄像头调试
工作平台:MTK8389 sensor:ov5648 今天调试这颗摄像头的心得就是:首先得把上电时序弄对,I2C才能通讯,然后就是ID都要写对.
- 用css实现条纹背景
我先额外的说一下怎么用CSS绘制三角形: 绘制三角形是把边框加粗,将元素的宽高都设为0,让其余的边框颜色透明,下面我们来看实现的代码: 先把边框的颜色设置成不同颜色: #div{ border-col ...
- Spark源码学习1.2——TaskSchedulerImpl.scala
许久没有写博客了,没有太多时间,最近陆续将Spark源码的一些阅读笔记传上,接下来要修改Spark源码了. 这个类继承于TaskScheduler类,重载了TaskScheduler中的大部分方法,是 ...
- C# List<T>用法
C# List<T>用法 所属命名空间:using System.Collections.Generic; List<T>类是 ArrayList 类的泛型等效类. 该类使用 ...
- C语言程序设计第十一次作业
同学们,一晃一个学期就过去了,第一节课时,我曾做过一个调查,没有一个同学在中学阶段接触过程序设计,也就是说,那时,大家都是零基础,或许只是听说过"C语言"这个词,但其他便一无所知了 ...