我有一个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
,如果我将其直接传递给UIViewController
,它会完美运行,但我无法将其传递给UINavigationViewController
,
有谁知道我怎么能这样做?
答案 0 :(得分: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;
}
}
答案 1 :(得分:0)
要使用{JINavigationController在您的情况下使用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;
}
}