0

我有一个 UIViewController,我必须将一个值(UIImage,NSString)传递给我正在使用的 UINavigationViewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    AppDetail *advc = [segue destinationViewController];
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        advc.appTitel = name;
        advc.appIcon = icon;
        advc.detailAppName = detileName;
        advc.appDescription = description;
        advc.appDeveloper = developer;
    }
}

将值传递给UIViewController,如果我直接将它传递给 a ,它可以完美地工作UIViewController,但我不能将它传递给 a UINavigationViewController,有人知道我该怎么做吗?

4

2 回答 2

2

我有来自 Apple segue 示例的示例代码。也许它有帮助。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Room Create"]) {
        // Prepare the settings view where the user inputs the 'serviceType' and local peer 'displayName'
        UINavigationController *navController = segue.destinationViewController;
        SettingsViewController *viewController = (SettingsViewController *)navController.topViewController;
        viewController.delegate = self;
        // Pass the existing properties (if any) so the user can edit them.
        viewController.displayName = self.displayName;
        viewController.serviceType = self.serviceType;
    }
} 
于 2013-09-29T19:20:22.593 回答
0

要在您的情况下使用 UINavigationController 传递值Segue,请尝试以下代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) 
    {
        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        AppDetail *advc = (AppDetail *)navController.topViewController;

        advc.appTitel = name;
        advc.appIcon = icon;
        advc.detailAppName = detileName;
        advc.appDescription = description;
        advc.appDeveloper = developer;
    }
}

如果您不使用 UINavigationController,则需要使用以下代码:

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

       // Get reference to the destination view controller
        AppDetail *advcc = segue.destinationViewController;

        advc.appTitel = name;
        advc.appIcon = icon;
        advc.detailAppName = detileName;
        advc.appDescription = description;
    }
}
于 2013-09-29T19:40:00.710 回答