2013-09-29 75 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; 
    } 
}