我正在尝试创建一个简单的天气应用程序,它使用JSON从OpenweatherMap获取数据并在UITableView中打印出来.但是,当我执行下面的代码并在numberOfRowsInSection方法中设置断点时,它返回0行.不知何故,该viewDidLoad方法在该numberOfRowsInSection方法之后调用,这就是为什么threeHoursForecast数组为空.有人可以帮我吗?
static NSString * const BaseURLString = @"http://api.openweathermap.org/data/2.5/forecast?q=Houston";
@interface HPViewController ()
@end
@implementation HPViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.threeHoursForecast = [[NSMutableArray alloc] init];
self.tableView.dataSource = self;
self.tableView.delegate = self;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:BaseURLString parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *data = [responseObject objectForKey:@"list"];
for (NSDictionary *forecastPerThreeHours in data) …Run Code Online (Sandbox Code Playgroud)