JSON 스트림을 풀고 두 개의보기 컨트롤러에 정보를 표시하는 기본 앱을 설정했습니다. 나는 루트 컨트롤러에 기반을 둔 스토리지 어레이를 주로 사용하고 있지만 작동 방법은 모범 사례는 아닙니다. 데이터 모델을 별도의 클래스로 옮겨서 앱 델리게이트에 할당하기로 결정했다. (싱글 톤을 사용할 수는 있지만 앱은 기본이며 배운다.)전역을 사용할 때 NSMuteablearray null
그래서 국가 클래스는
@interface Country : NSObject {
NSString *countryName;
NSString *countryDetail;
NSMutableArray *countryList;
UIImage *countryFlag;
}
@property (nonatomic, retain) NSString *countryName;
@property (nonatomic, retain) NSString *countryDetail;
@property (nonatomic, retain) UIImage *countryFlag;
@property (nonatomic, retain) NSMutableArray *countryList;
하고 각 속성은하는 .m에서 다음
@class RootController;
@class Country;
@interface FO_InfoAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navController;
RootController *viewController;
Country *myCountry;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RootController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@property (nonatomic,retain) Country *myCountry;
그리고 .H AppDelegate에에서하는 .m
에 synthized되어
#import "Country.h"
@synthesize myCountry;
myCountry = [[Country alloc] init];
그런 다음 #define을 사용하여 필요한 클래스에서 전역을 공유합니다.
#define FOAppDelegate ((FO_InfoAppDelegate *)[[UIApplication sharedApplication] delegate])
두 개의 다른 json 피드를 처리하는 두 개의 구문 분석 클래스가 있습니다. 동일한 소스의 다른 데이터.
내 원래 구성 나는 parseclass.h에 rootcontroller에서 호출 된 메소드가 있습니다.
- (void)querycountrieslistwithViewCont:(UIViewController *)controller;
그런 다음 구현에 나는 JSON의 몇 가지 분석을하고 원래 선언하고 일하는 방법이이었다 루트 컨트롤러 에 alloced 된 NSmuteablearray에 데이터를 전달합니다.
[FOAppDelegate.myCountry.countryList addObject:[country valueForKeyPath:@"country.slug"]];
이 :
NSArray *countries = [jparser objectWithString:fco_content error:&error];
for (NSDictionary *country in countries) {
[viewController.countryName addObject:[country valueForKeyPath:@"country.slug"]]
는 이제 데이터 모델 내 새로운 디자인에 내가 구문 분석 클래스 그래서 난 마지막 줄에 변경 국가 클래스의 정보를 저장할
결과 배열은 jQuery과에 공급 배열이 null로 나열되는 결과가 나타납니다. 그들은 둘 다 다른 장소에서 방금 액세스 한 NSMuteablearray입니다. 조금 어이가 혼란스러워!
실제로 countryList를 설정하고 있습니까? 당신은 그것을 선언하지만 어디에도 알 수없는 배열을 할당하고 초기화하지 마십시오. – occulus
당신은 NSString으로 선언 한 countryName이라는 이름을 가지고 있지만 나중에 addObject :를 호출합니다. 그들은 실제로 같은 이름을 갖는 다른 것들입니까? – occulus