准备segue传递数据选择器

时间:2013-02-23 00:21:39

标签: iphone ios selector segue

我正在尝试使用此代码通过segue传递数据:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"exerciseDetailDescription"]) {
    SoulExerciseDetailQuarViewController *destination = segue.destinationViewController;
    if ([destination respondsToSelector:@selector(setOverview:)]) {
        NSDictionary *overview = @{@"name" : [_exercise objectForKey:@"name"], @"longDescription" : [_exercise objectForKey:@"longDescription"]};
        [destination setValue:overview forKey:@"overview"];

    }
}
else if ([segue.identifier isEqualToString:@"exerciseDetailGear"]) {
    SoulExerciseDetailTriaViewController *destination = segue.destinationViewController;
    if ([destination respondsToSelector:@selector(setSelectedGearString:)]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        NSString *selectedGearString = cell.detailTextLabel.text;
        [destination setValue:selectedGearString forKey:@"selectedGearString"];

    } 
}
else if ([segue.identifier isEqualToString:@"exerciseDetailCategory"]) {
    SoulExerciseDetailDuaViewController *destination = segue.destinationViewController;
    if ([destination respondsToSelector:@selector(setSelectedCategoryString:)]) {
        NSLog(@"Go");
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        NSString *selectedCategoryString = cell.detailTextLabel.text;

        [destination setValue:selectedCategoryString forKey:@"selectedCategoryString"];

    }
}}

因此,如果它响应segue目的地中的setter,则允许传输数据。

奇怪的是,第一个响应正确,但在第二个和第三个,它表示目标视图控制器没有响应那些setter

例如,在第三个中,未显示nslog。

1 个答案:

答案 0 :(得分:1)

以前的评论回答:

NSLog目的地类:

NSLog(@"class name: %@", NSStringFromClass([destination class]));

我敢打赌,这课不是你的想法。

OP:“它说导航控制器”

这不是你所期望的,对吗?因此,弄清楚为什么错误的东西被实例化。