我正在尝试使用故事板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"];
}
}发布于 2011-10-25 13:31:46
除非您将该indexPath作为ivar,否则作用域中不存在这样的变量。
如果想要在UITableView中获取所选行的indexPath,请使用:
- (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"];
}
}发布于 2012-09-27 01:26:23
这个技巧效果很好,下面是我如何使用它将解析的元素拉入web视图的一个示例。
.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"];
}
}https://stackoverflow.com/questions/7884764
复制相似问题