自定义UITableViewCell的accessoryView 判断哪个Button按下
2个回答
2016-01-11 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517184
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
okj没有看到,对不起,拒绝吧。方法如下:
1、创建自定义按钮,并设为AccessoryView:
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIImage *image= [ UIImage imageNamed:@"delete.png" ];
UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
CGRect frame = CGRectMake( 0.0 , 0.0 , image.size.width , image.size.height );
button. frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal ];
button. backgroundColor = [UIColor clearColor ];
[button addTarget:self action:@selector(buttonPressedAction forControlEvents:UIControlEventTouchUpInside];
cell. accessoryView = button;
}
2、如果将Button加入到cell.contentView中,也是可以的。
cell.contentView addSubview:button];
3、在Tap时进行判断,得到用户Tap的Cell的IndexPath
- (void)buttonPressedAction id)sender
{
UIButton *button = (UIButton *)sender;
(UITableViewCell*)cell = [button superview];
int row = [myTable indexPathForCell:cell].row;
}
4、对于加到contentview里的Button:
(UITableViewCell*)cell = [[button superview] superview];
1、创建自定义按钮,并设为AccessoryView:
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIImage *image= [ UIImage imageNamed:@"delete.png" ];
UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
CGRect frame = CGRectMake( 0.0 , 0.0 , image.size.width , image.size.height );
button. frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal ];
button. backgroundColor = [UIColor clearColor ];
[button addTarget:self action:@selector(buttonPressedAction forControlEvents:UIControlEventTouchUpInside];
cell. accessoryView = button;
}
2、如果将Button加入到cell.contentView中,也是可以的。
cell.contentView addSubview:button];
3、在Tap时进行判断,得到用户Tap的Cell的IndexPath
- (void)buttonPressedAction id)sender
{
UIButton *button = (UIButton *)sender;
(UITableViewCell*)cell = [button superview];
int row = [myTable indexPathForCell:cell].row;
}
4、对于加到contentview里的Button:
(UITableViewCell*)cell = [[button superview] superview];
推荐于2016-07-28 · 知道合伙人互联网行家
关注
展开全部
UITableview的开发中经常要自定义Cell右侧的AccessoryView,把他换成带图片的按钮,并在用户Tap时判断出是哪个自定义按钮被按下了。
创建自定义按钮,并设为AccessoryView
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIImage *image= [ UIImage imageNamed:@"delete.png" ];
UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
CGRect frame = CGRectMake( 0.0 , 0.0 , image.size.width , image.size.height );
button. frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal ];
button. backgroundColor = [UIColor clearColor ];
[button addTarget:self action:@selector(buttonPressedAction forControlEvents:UIControlEventTouchUpInside];
cell. accessoryView = button;
}
如果将Button加入到cell.contentView中,也是可以的。
cell.contentView addSubview:button];
在Tap时进行判断,得到用户Tap的Cell的IndexPath
- (void)buttonPressedAction id)sender
{
UIButton *button = (UIButton *)sender;
(UITableViewCell*)cell = [button superview];
int row = [myTable indexPathForCell:cell].row;
}
对于加到contentview里的Button,
(UITableViewCell*)cell = [[button superview] superview];
创建自定义按钮,并设为AccessoryView
if (cell == nil) {
cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
UIImage *image= [ UIImage imageNamed:@"delete.png" ];
UIButton *button = [ UIButton buttonWithType:UIButtonTypeCustom ];
CGRect frame = CGRectMake( 0.0 , 0.0 , image.size.width , image.size.height );
button. frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal ];
button. backgroundColor = [UIColor clearColor ];
[button addTarget:self action:@selector(buttonPressedAction forControlEvents:UIControlEventTouchUpInside];
cell. accessoryView = button;
}
如果将Button加入到cell.contentView中,也是可以的。
cell.contentView addSubview:button];
在Tap时进行判断,得到用户Tap的Cell的IndexPath
- (void)buttonPressedAction id)sender
{
UIButton *button = (UIButton *)sender;
(UITableViewCell*)cell = [button superview];
int row = [myTable indexPathForCell:cell].row;
}
对于加到contentview里的Button,
(UITableViewCell*)cell = [[button superview] superview];
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询