그래서 JSON 피드를 읽을 앱을 작성 중입니다. 내 응용 프로그램 : didFinishLaunchingWithOptions에서 JSON 문자열을 다운로드하고 로컬 NSString 변수에 저장하는 코드를 작성했습니다. 그런 다음 해당 문자열을 ListingsViewController (NavigationController의 루트 VC 임)로 전달합니다. ListingsViewController에서 JSON 데이터를 인쇄 할 때 viewDidLoad가로드되고 있다고 생각하게 만드는 me (null)이 표시됩니다. - 비논리적 인 것처럼 보입니까? 그래서 여기application : didFinishLaunchingWithOptions before viewDidLoad
내 응용 프로그램입니다 : 다음과 같이 didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Grab the feeds
NSURL *jsonURL = [NSURL URLWithString:@"http://www.shoofeetv.com/iphonexml/view/all_channels.json"];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
// Pass jsonData to the ListingsViewController
ListingsViewController *listingsViewController = [[ListingsViewController alloc] initWithNibName:@"ListingsViewController" bundle:nil];
listingsViewController.jsonData = jsonData;
[listingsViewController release];
// Display the navigation controller
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
내있는 viewDidLoad 방법은 다음과 같습니다
- (void)viewDidLoad {
self.navigationItem.title = @"Listings";
UIBarButtonItem *checkinButton = [[UIBarButtonItem alloc]
initWithTitle:@"Check In"
style:UIBarButtonItemStylePlain
target:self
action:@selector(switchView)];
self.navigationItem.rightBarButtonItem = checkinButton;
[checkinButton release];
NSLog(@"%@", self.jsonData);
[super viewDidLoad];
}
는 공통의 해결책이 있는지 확인하는 것입니다 있습니다 MainWindow.xib에의 응용 프로그램 위임이 파일 소유자에게 연결되어야합니다. 내 것은 이미 연결되어 있습니다.
어떤 도움을 주셔서 감사합니다!
감사합니다.
아 또한, 내가 넣어 두 NSLogs ( 다양한 네트워크 조건에서 귀하의 응용 프로그램을 테스트합니다 사과 ) 네트워크 오류를 비동기 JSON 데이터를로드하고 처리 할 필요가 있음을 기억 각 함수에서 viewDidLoad NSLog가 먼저 나타납니다. 감사합니다! – darksky