gpt4 book ai didi

ios - 检测在 UITableView 中从哪个 Cell 按下 UIButton

转载 作者:行者123 更新时间:2023-11-29 02:01:21 27 4
gpt4 key购买 nike

我有两个具有相同 UIButton 的自定义 UItableViewCell ,如何确定从哪个单元格调用 UIButton

附言我不想使用两种不同的方法。

cellForRowAtIndexPath Method.

if (indexPath.row==1) {
static NSString *cellIdentifier = @“CustomeCell1“;

NewsFeedCell1 *cell = (NewsFeedCell1 *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.btnPrivacy.tag = indexPath.row;
[cell.btnPrivacy addTarget:self action:@selector(btnPrivacyClicked:) forControlEvents:UIControlEventTouchUpInside];

}
else
{
static NSString *cellIdentifier = @"CustomeCell2”;

NewsFeedCell2 *cell = (NewsFeedCell2 *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.btnPrivacy.tag = indexPath.row;
[cell.btnPrivacy addTarget:self action:@selector(btnPrivacyClicked:) forControlEvents:UIControlEventTouchUpInside];

}

Button click Methods.

-(IBAction)btnPrivacyClicked:(UIButton *)sender
{
NSLog(@"Privacy Clicked at : %ld",(long)sender.tag);

// Here Determine From Which Cell UiButton Is Clicked.
NewsFeedCell1 *cell = (NewsFeedCell1 *)[self.HomeTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag inSection:0]];

最佳答案

// *** Use Following code to detect `Cell` ***
CGPoint buttonPosition = [button convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
[self.tableView cellForRowAtIndexPath:indexPath];

关于ios - 检测在 UITableView 中从哪个 Cell 按下 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30350466/

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