首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Storyboard?

如何使用Storyboard?
EN

Stack Overflow用户
提问于 2011-10-25 12:36:07
回答 2查看 2.3K关注 0票数 2

我正在尝试使用故事板segue而不是didSelectRowAtIndex。

这就是我所拥有的,但是这个方法不能识别indexPath.row。有没有其他方法可以让我用来做同样的事情?

代码语言:javascript
复制
-(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"];
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-25 13:31:46

除非您将该indexPath作为ivar,否则作用域中不存在这样的变量。

如果想要在UITableView中获取所选行的indexPath,请使用:

代码语言:javascript
复制
- (NSIndexPath *)indexPathForSelectedRow

以上调整后的代码如下:

代码语言:javascript
复制
-(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"];
    }
}
票数 5
EN

Stack Overflow用户

发布于 2012-09-27 01:26:23

这个技巧效果很好,下面是我如何使用它将解析的元素拉入web视图的一个示例。

.h文件

代码语言:javascript
复制
@property (strong, nonatomic) NSString *url;
@property (strong, nonatomic) UIWebView *webView;

.m文件

代码语言:javascript
复制
-(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"];

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7884764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档