gpt4 book ai didi

ios - 如何识别 TableView 内自定义单元格中单击按钮的行索引和节号

转载 作者:行者123 更新时间:2023-11-29 10:35:53 25 4
gpt4 key购买 nike

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"CustomCell";

cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner: self options: nil ];
cell = [nib objectAtIndex:0];


}
//cell.lblName.text = [items objectAtIndex:indexPath.row];
NSMutableDictionary *dic = [items objectAtIndex:indexPath.row];
cell.imgface.image = [dic objectForKey:@"Image"];
cell.imgface.layer.cornerRadius = cell.imgface.frame.size.width / 2;
cell.imgface.layer.borderWidth = 3.0f;
cell.imgface.layer.borderColor = [UIColor whiteColor].CGColor;
cell.imgface.clipsToBounds = YES;
cell.lblName.text = [dic objectForKey:@"Name"];
[cell.btnPhone setTitle:[dic objectForKey:@"Phone"] forState:(UIControlStateNormal)];
cell.btnPhone.tag = indexPath.row;
cell.btnstar.tag = indexPath.row;
[cell.btnPhone addTarget:self action:@selector(dial:) forControlEvents:(UIControlEventTouchUpInside)];
[cell.btnstar addTarget:self action:@selector(toggleimage:) forControlEvents:UIControlEventTouchUpInside];
if (indexPath.section == 0)
{
star = [UIImage imageNamed:@"Star-Favorites.png"];
[cell.btnstar setBackgroundImage:star forState:UIControlStateNormal];
}
else
{
star = [UIImage imageNamed:@"keditbookmarks.png"];
[cell.btnstar setBackgroundImage:star forState:UIControlStateNormal];

}

return cell;
}

最佳答案

write below code in button IBAction and you will get indexpath.row and indexpath.section

CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
NSLog(@"selected tableview row is %d",indexPath.row);

关于ios - 如何识别 TableView 内自定义单元格中单击按钮的行索引和节号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27148021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com