我有一个实例变量数组:
@interface ChannelsVC ()
{
NSArray *arrayofFrequencies;
}
}
@end
@implementation ChannelsVC
......
在“viewDidLoad”中进行分配
arrayofFrequencies=[[NSArray alloc]init];
然后,我将来自 JSON 数据源的数据插入到数组中:
-(void)GetFrequencies{
NSString *urla=@"http://xxxxxxxx";
NSString *uria = [urla stringByAppendingString:self.lien_satellite];
NSURL *urlFrequencies= [ NSURL URLWithString:uria];
NSLog(@"Frequencies URI: %@",uria); //correct URI
NSURLRequest *request = [NSURLRequest requestWithURL:urlFrequencies];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
arrayofFrequencies=[JSON valueForKeyPath:@"frequency"];
NSLog(@"Frequencies count: %lu", (unsigned long)[arrayofFrequencies count]);//the count here is correct, I have data in the array
} failure:nil];
[operation start];
}
问题是当想要制作一个 UITableView 时,它的节数是 '[arrayofFrequencies count];' ,它总是返回 '0' !它是一个实例变量,它在“GetFrequencies”函数之外返回零。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"number of sections %ld",(long)[arrayofFrequencies count]); // always returns 0
return [arrayofFrequencies count];
}
难道我做错了什么?
谢谢你的帮助。
控制台输出:
013-06-25 12:58:00.163 Frequencies[840:c07] number of sections 0
2013-06-25 12:58:00.165 Frequencies[840:c07] number of sections 0
2013-06-25 12:58:00.641 Frequencies[840:c07] Frequencies count: 4