我正在尝试使用以下代码通过数据进行数据传递:

- (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目的地中找到的设置器,则允许数据传输。

奇怪的是,第一个响应正确,但是在第二和第三个响应中,它表示目标视图控制器未响应那些设置程序

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

最佳答案

先前评论的答案:

NSLog目标类:

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


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

OP:“它说导航控制器”

您不期望哪个,对吗?因此,弄清楚为什么实例化了错误的事情。

09-27 03:27