0

我正在尝试将值(UIImage、NSString)传递给另一个 ViewController,但它不起作用。

我的代码如下所示:

第一个 ViewController.m

#import 2nd ViewController.h

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

第二个 ViewController.h

#import <UIKit/UIKit.h>

@interface AppDetail : UIViewController

@property (strong, nonatomic) NSString *appTitel;
@property (strong, nonatomic) UIImage *appIcon;
@property (strong, nonatomic) NSString *detailAppName;
@property (strong, nonatomic) NSString *appDescription;

@end

第二个 ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = self.appTitel;
    self.appIconImageView.image = self.appIcon;
    self.detailAppNameTextView.text = self.detailAppName;
    self.appDescriptionTextView.text = self.appDescription;
}

但我总是得到(null)所有的价值!

我究竟做错了什么??

4

2 回答 2

2

正确的:

- (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;
    }
}

下面的代码是您不使用 storyboard 时的代码:

AppDetail *advc = [[AppDetail alloc] init];
于 2013-09-29T10:09:16.903 回答
1

更正这些行

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //AppDetail *advc = [[AppDetail alloc] init];
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        AppDetail *advc     = segue.destinationViewController; //ADD THIS
        advc.appTitel       = name;
        advc.appIcon        = icon;
        advc.detailAppName  = detileName;
        advc.appDescription = description;
    }
}
于 2013-09-29T10:08:54.550 回答