Я борюсь с UITableView, который у меня раньше работал, и каким-то образом я его сломал! Это часть курса Пола Хегарти.
Симптом заключается в том, что представление загружается, но оно пустое. Я явно неправильно понимаю что-то довольно простое.
Насколько я понимаю, два ключевых метода: 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
А второй находится в 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;
}