以前作業していたUITableViewに苦労していて、どういうわけか壊れてしまいました。これは、PaulHegartyのコースのユニットの一部です。
症状は、ビューが読み込まれるが空であるということです。私は明らかにかなり基本的なことを誤解しています。
私が理解している限り、2つの重要な方法は1です。セクションの行数は、私の場合はゼロを返しますが、これは間違っていると思います。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// #warning Incomplete method implementation.
// Return the number of rows in the section.
NSLog(@"TopPlaces %@",self.topPlaces);
//return 100;
return [self.topPlaces count];
}
上記の理由により、行がないため、次のメソッドが呼び出されることはありません。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
2つ目はViewDidLoad内にあり、データをコンソールに記録でき、すべてが正常に表示されます。つまり、私のデータはViewDidLoad内で生成されます
- (void)viewDidLoad
{
[super viewDidLoad];
dispatch_queue_t dowloadQueue = dispatch_queue_create("flick downloader", NULL);
dispatch_async(dowloadQueue, ^{
NSArray *topPlaces = [FlickrFetcher topPlaces];
//NSLog(@"Array is %@",topPlaces); // array is OK here
dispatch_async(dispatch_get_main_queue(), ^{
NSSortDescriptor *woeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"_content" ascending:YES];
NSArray *woeDescriptors = @[woeDescriptor];
NSArray *sortedReturns = [topPlaces sortedArrayUsingDescriptors:woeDescriptors];
self.topPlaces = sortedReturns;
//all the data is present here, count is 100 and array will log to console
NSLog(@"count here is %u",[self.topPlaces count]);
});
});
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
}