您的位置:首页 > 产品设计 > UI/UE

UITableCell自定义按钮判断点击哪一行

2015-06-22 10:13 411 查看

UITableCell自定义按钮事件响应, 判断点击哪一行.

cell 默认有一个AccessoryView, 可用于添加按键, 当然也可以添加到cell的contentView上, 或直接添加到cell上:

if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier1];
UIButton *btnDown = [[UIButton alloc]initWithFrame:CGRectMake(200, 0, 44, 44)];
[btnDown addTarget:self action:@selector(btnActionOfCell:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btnDown]; //此方法注意定义按钮x坐标.
//或[cell.contentView addSubview:btnDown];
//或[cell setAccessoryView:btnDown];
}


响应事件获取点击的cell:

(UITableViewCell*)cell = [button superview]; //对于加到cell 或 cell.AccessoryView.
(UITableViewCell*)cell = [[button superview] superview]; //对于加到contentview里的Button.


通过cell获取cell在表的哪一行

int row = [myTable indexPathForCell:cell].row;

—–完——
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: