如何得到自定义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 ...
随机推荐
- 手把手教你在Ubuntu上安装Apache、MySql和PHP
1:首先安装apache:打开终端(ctrl+Alt+t), 输入命令:sudo apt-get install apache2即可安装, 安装完后,打开浏览器,在地址栏输入:localhost或者h ...
- 谈谈eclipse使用技巧
俗话说的好啊,“工于利启事,必先善其器”,如果说你的编程功底是一个枪法的话,那么强大的eclipse就是android战士们最好的武器. 这里,我们来总结eclipse的使用技巧,从而使我们的编程达到 ...
- cheap gucci bags for women finish fashion jewellery has to move
Is certainly his dresser seem or dress creation process into video clip. Bus dropped???? Especially ...
- extjs combobox
states.js中 Ext.example.states=[ ['AL','ALabama','The Heart of Dixie'], ['AK','Alaska','The Land of t ...
- Socket异步存储示例
异步客户端存储示例: using System; using System.Net; using System.Net.Sockets; using System.Threading; using S ...
- css3旋转
首先创建一个容器如div,然后设置其相关的3d属性,主要是三个1.perspective 透视,值越小3D感越强,值越大视觉正常.2.perspective-origin,透视点一般居于容器的中心.3 ...
- js键盘事件
弱鸡今天在写键盘事件,发生一个小bug,排查了1小时(">皿<)可恶的浏览器竟然还不报错!!原因是将e.ctrlKey写成了e.ctrLKey,o(゚Д゚)っ 想想都要生气< ...
- PHP 关于SQL注入的防范措施。
最近在使用框架的时候还是有点不安,不知道框架的设计者有没有考虑到SQL-Injection的问题,我在顶层需不需要做一些必要的过滤等等,由 此我特意的去StackOverflow看了下,真是获益良多, ...
- 一个比较综合的项目--》>图片缓存,下拉刷新等
在办公室电脑(E:\workspace\23\Collections)
- 学习NSRulerView
NSRulerMarker 有个imageOrigin是描述Marker中image的位置的: 在horizontal的ruler中,imageOrigin的x坐标是跟marker的location进 ...