gpt4 book ai didi

iphone - 如何使用 Storyboard?

转载 作者:行者123 更新时间:2023-12-03 20:32:01 25 4
gpt4 key购买 nike

我正在尝试使用 Storyboard segue 而不是 didSelectRowAtIndex。

这就是我所拥有的,但此方法无法识别indexPath.row。我可以用其他方法来做同样的事情吗?

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
SpecificExerciseTableViewController *upcomingViewController = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"Web"])
{
upcomingViewController.exerciseArray = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"exercises"];
upcomingViewController.muscleName = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
}
}

最佳答案

除非您将该 indexPath 作为 ivar,否则范围内不存在此类变量。

如果您想获取 UITableView 中所选行的索引路径,请使用:

- (NSIndexPath *)indexPathForSelectedRow

上面调整后的代码:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

SpecificExerciseTableViewController *upcomingViewController = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"Web"])
{
upcomingViewController.exerciseArray = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"exercises"];
upcomingViewController.muscleName = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
}
}

关于iphone - 如何使用 Storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com