我正在遵循http://www.appcoda.com/fetch-parse-json-ios-programming-tutorial/中提供的教程,我下载了代码并尝试运行它。应用启动时,我得到的是空白表格视图。我应该从网站获取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];
}
谁能告诉我我想念的东西吗?
最佳答案
决不会从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?
关于ios - 在iOS中获取并解析JSON,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27870543/