如何使用故事板?

发布于 2024-12-11 21:10:17 字数 609 浏览 5 评论 0原文

我正在尝试使用故事板 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"];
    }
}

I'm trying to use storyboards segue instead of didSelectRowAtIndex.

This is what I have, but this method does not recognize indexPath.row. Is there an alternative I can use to do the same thing?

-(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"];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里人 2024-12-18 21:10:17

除非您将该 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"];
    }
}

Unless you have that indexPath as an ivar, no such variable exists in the scope.

If you would like to get the indexPath for the selected row in a UITableView use:

- (NSIndexPath *)indexPathForSelectedRow

The adjusted code for above:

-(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"];
    }
}
硬不硬你别怂 2024-12-18 21:10:17

的示例

这个技巧效果很好,下面是我如何使用它将解析的元素拉入网页视图.h 文件

@property (strong, nonatomic) NSString *url;
@property (strong, nonatomic) UIWebView *webView;

.m 文件

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if ([segue.identifier isEqualToString:@"WebViewSegue"]) {

        WebViewController *webViewController = segue.destinationViewController;
        webViewController.url = (self.parseResults)[indexPath.row][@"link"];
        webViewController.title = (self.parseResults)[indexPath.row][@"title"];

    }
}

This trick works fine,heres an example of how I used it to pull parsed elements into a web view

.h file

@property (strong, nonatomic) NSString *url;
@property (strong, nonatomic) UIWebView *webView;

.m file

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if ([segue.identifier isEqualToString:@"WebViewSegue"]) {

        WebViewController *webViewController = segue.destinationViewController;
        webViewController.url = (self.parseResults)[indexPath.row][@"link"];
        webViewController.title = (self.parseResults)[indexPath.row][@"title"];

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文