我有一个表格视图,其中每个单元格包含一个按钮。我不使用didSelectRowAtIndexPath委托,但我的自定义方法的按钮操作。我希望点击每个单元格内的按钮时,该单元格应该突出显示或更改颜色,并在单击某个其他单元格中的按钮时使其恢复到正常状态(颜色)。(使该单元格突出显示)。我的按钮操作方法是:可用视图单元格高亮
- (void)SelectButtonTapped:(UIButton *)button
{
self.tabBarController.tabBar.userInteractionEnabled = YES;
AppDelegate *proDel = [[UIApplication sharedApplication]delegate];
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
//MyCustomCell *cell = (MyCustomCell *)button.superview.superview;
NSIndexPath *indexPath = [homeTable indexPathForCell:cell];
//cell.backgroundColor = [UIColor lightGrayColor];
//[homeTable setNeedsDisplayInRect:[homeTable rectForRowAtIndexPath:indexPath]];
DetailViewController *objDetail=[[DetailViewController alloc] init];
Home *tempSearchObj=(Home *)[profileArray objectAtIndex:indexPath.row];
objDetail.firstName=tempSearchObj.userName;
objDetail.userImageUrl=tempSearchObj.imageUrl;
objDetail.passedProfileID = tempSearchObj.profileID;
plsSelectLabel.text = [NSString stringWithFormat:@"%@",objDetail.firstName];
proDel.globalName = plsSelectLabel.text;
proDel.globalProfileId = objDetail.passedProfileID;
}
但是,这似乎并不奏效。任何帮助,将不胜感激!!
这将使单元格在单元格上单击时突出显示,但我希望单击该单元格的子视图的按钮 – user1845209
@ user1845209如果将标记添加到您的单元格中,可以在方法中创建单元格的引用按钮作为indexPath.row添加按钮时。 –
@ user1845209我已更新我的答案。现在试试.. –