У меня есть два пользовательских UItableViewCell
с одинаковыми UIButton
, как определить, из какой ячейки UIButton
называется?Обнаружение, из которого ячеек, UIButton был нажат в UITableView
P.S. Я не хочу использовать два разных метода.
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];
}
Кнопка нажмите методы.
-(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. http://stackoverflow.com/a/22827645/790842 и здесь 2. http://stackoverflow.com/a/30029818/790842. Это, безусловно, поможет. Cheers – iphonic
Если вы имеете в виду, что _type_ ячейки (класс NewsFeedCell1 или NewsFeedCell2), используйте 'isKindOfClass'. – Anna