2013-09-29 117 views
0

我想将值(UIImage,NSString)传递给另一个ViewController,但它不会工作。将值传递给另一个ViewControler

我的代码如下所示:

1 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)所有值!

我在做什么错?

回答

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

低于它,当你不使用故事板代码:

AppDetail *advc = [[AppDetail alloc] init]; 
+0

OK,谢谢! –

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