我的表格视图中有一个带有按钮的自定义位置单元格。当我按下按钮时,我希望它与该位置的啤酒细节保持一致。我正在使用情节提要,我可以通过使用以下代码将整个单元格连接到 BeerTableViewController 来使其工作
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"beer"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
BeerTableViewController *beer = (BeerTableViewController *)[segue destinationViewController];
Location *location = [self.location_results objectAtIndex:indexPath.row];
beer.location_id = location.location_id;
beer.location_name = location.location_name;
}
}
但是当我从按钮而不是整个单元格创建一个转场时,无论单击哪一行,它总是与第一行转场。显然,我不会在按下按钮的情况下通过该行。我在这里查看了许多解决方案,但没有找到明确的答案。有任何想法吗?
编辑 1
我正在 TableViewController 中尝试以下代码
-(void)beerTapsPressed:(id)sender {
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *clickedButtonPath = [self.tableView indexPathForCell:clickedCell];
[self performSegueWithIdentifier:@"beer" sender:clickedButtonPath];
}
我有 ctrl + 将情节提要中的一个 segue 从 TableView 拖到 DetailView 并将 segue 命名为“beer”,并且我在单元格中有一个名为“beerTaps”的按钮,但无论我点击哪一行,我仍然只能获得第 1 行的详细信息。