2011-08-19 5 views
0

iPhone 앱에서 두 개의보기를 통해 문자열을 전달하려고합니다. 나는 - 안녕 문자열을 복구 할 내 두 번째보기에 있습니다 보기를 통해 문자열을 전달하는 iPhone SDK

#import <UIKit/UIKit.h> 
#import "MBProgressHUD.h" 
#import "RootViewController.h" 

@interface PromotionViewController : UITableViewController { 

    NSString *currentCat; 
} 

@property (nonatomic, retain) NSString *currentCat; 

@end 

그리고 .mi에서

가 있습니다

@synthesize currentCat; 

그러나, 첫 번째보기 컨트롤러에서 내가 시도하고 설정할 때 를 찾을 수없는 클래스 방법 + currentCat : 세 번째 줄은 나에게 있습니다

PromotionViewController *loadXML = [[PromotionViewController alloc] initWithNibName:@"PromotionViewController" bundle:nil]; 
     [self.navigationController pushViewController:loadXML animated:YES]; 
     [PromotionViewController currentCat: @"Test"]; 

그건 : 그 변수 I는 찾을 수 없습니다 오류내가 뭘 잘못 했니?

NSString* myString = controller.currentCat; // where controller is an instance of PromotionViewController 

답변

1

톰, 문제를 코드가 나타납니다에서이 방법 속성이고하지

0

당신은이 같은 문자열을 얻을 필요 클래스에 대한 정적 메서드 호출을 사용하여 문자열을 설정하려고합니다. 이것은 currentCat라는 정적 메서드를 구현 한 경우 작동합니다.

나는 이것이 당신이 원하는 것이라고 생각하지 않습니다. 문제를 해결하는 방법은 아래를 참조하십시오. 그것을해야

[PromotionViewController currentCat:@"Test"]; 
//This will not work as it is calling the class itself not an instance of it. 

[loadXml setCurrentCat:@"Test"]; 
//This will work. Keep in mind if you are going to call the objective-c 
//synthesize setting directly you will need to capitalize the first letter 
//of your instance variable name and add "set" to the front as I've done. 

//Alternatively in objective-c 2.0 you can also use 
//the setter method with the . notation 

loadXml.currentCat = @"Test"; 
//This will work too 
0

당신이 할 필요가 :

loadXML.currentCat = @"Test"; 
0
PromotionViewController *loadXML = [[PromotionViewController alloc] initWithNibName:@"PromotionViewController" bundle:nil]; 
[loadXML setCurrentCat: @"Test"]; 
[self.navigationController pushViewController:loadXML animated:YES]; 

.