2015-01-09 120 views
0

我正在按照http://www.appcoda.com/fetch-parse-json-ios-programming-tutorial/中提供的教程進行操作,我下載了代碼並嘗試運行它。當應用程序啓動時,我得到空白表視圖。我應該從網站獲取JSON數據並將其顯示在表格視圖中。在iOS中獲取和解析JSON

不知何故,取組方法是沒有得到所謂的在我看來,做負載方法

@interface MasterViewController() <MeetupManagerDelegate> { 
NSArray *_groups; 
MeetupManager *_manager; 
} 

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 

_manager = [[MeetupManager alloc] init]; 
_manager.communicator = [[MeetupCommunicator alloc] init]; 
_manager.communicator.delegate = _manager; 
_manager.delegate = self; 

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(startFetchingGroups:) 
              name:@"kCLAuthorizationStatusAuthorized" 
              object:nil]; // this should fetch the groups from the website but it isnt doing anything 

} 

#pragma mark - Notification Observer 
- (void)startFetchingGroups:(NSNotification *)notification 
{ 
[_manager fetchGroupsAtCoordinate:self.locationManager.location.coordinate]; 
} 

誰能告訴我,我缺少的是什麼?

回答

1

永遠不會從AppDelegate.m發佈NSNotificationCenter「kCLAuthorizationStatusAuthorized」。

當應用程序運行時,它應該問你是否進行授權,然後才能使用位置瀏覽Meetup。出於某種原因,它不是要求授權。這可能與代碼數年前相比,與iOS8相比已經過時了。

試試這個教程,這是一個有點新:http://www.appcoda.com/parse-xml-and-json-web-service/

而且,只是看如何剛剛從一個文本文件解析JSON(頂端回答):How do I parse JSON from a file in iOS?