使用“prepareForSegue”将字符串返回给View Controller

时间:2013-07-23 17:44:24

标签: ios segue

我的代码是:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
 {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {

       NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
       NSString *string = [feeds[indexPath.row] objectForKey: @"description"];
       NSLog(@"Description : %@" , string);

        [[segue destinationViewController] " WHAT TO CODE IN HERE ? "];

    } }

我需要在viewController中的NSLog中显示“string”。 有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

您需要向目标视图控制器添加属性以设置所需的字符串。然后,您将能够从目标视图控制器引用其值:

@interface DestinationViewController
...
@property (nonatomic, readwrite) NSString *theString;
@end

现在你可以打电话了

[[segue destinationViewController] setTheString:string];

DestinationControllerType *dest = [segue destinationViewController];
dest.theString = string;

然后在目标视图显示时引用theString