【发布时间】:2015-05-20 13:01:38
【问题描述】:
我有两个自定义 UItableViewCell 和相同的 UIButton ,如何确定从哪个单元格调用 UIButton ?
附:我不想使用两种不同的方法。
cellForRowAtIndexPath 方法。
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];
}
按钮点击方法。
-(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]];
【问题讨论】:
-
在此处查看我的答案 1.stackoverflow.com/a/22827645/790842 和此处 2.stackoverflow.com/a/30029818/790842。它肯定会有所帮助。干杯
-
如果您指的是哪个 type 单元格(NewsFeedCell1 或 NewsFeedCell2 类),请使用
isKindOfClass。
标签: ios uitableview