2013-09-29 4 views
0

값 (UIImage, NSString)을 다른 ViewController로 전달하려고 시도했지만 작동하지 않습니다.다른 ViewController에 값 전달

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

2 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 

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

그러나 I :

내 코드는 다음과 같습니다 01을 얻다 모든 값에 대해!

내가 뭘 잘못하고 있니?

답변

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

확인, 감사합니다! –

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; 
    } 
} 
관련 문제