我有一個表格視圖,其中每個單元格包含一個按鈕。我不使用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我已更新我的答案。現在試試.. –