objective c - populate UITableView -
I am struggling with a UITableView that I had worked before and somehow I broke it! This is part of a unit in the course of Paul Hegarty's
The symptom is that the scene loads but it is empty I am clearly being misunderstood in some wrong way.
By now I understand that the two main methods are the count of 1 section rows which are returning zero in my case, which I know is wrong!
- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section {// incomplete legal implementation #warning. // Return the number of rows in the section NSLog (@ "top place% @", manually top); // return 100; Return [self. Top place count]; } The following method is never called because of the above because there are no rows
- (UITableViewCell *) tableView :. (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath And the second is within the viewDidLoad, where I can enter your data for the console and gives everything looks fine. That is, my data is generated in viewdload
- (zero) viewDidoadload [[Super Viewedload]; Dispatch_queue_t dowloadQueue = dispatch_queue_create ("Flick Downloader", NULL); dispatch_async (dowloadQueue, ^ {NSArray * topPlaces = [FlickrFetcher topPlaces]; // array right here dispatch_async (dispatch_get_main_queue (), ^ {NSSortDescriptor * woeDescriptor is = [[; // NSLog (@, topPlaces) "array% @" NSSortDescriptor alloc] initWithKey:: @ "_ materials" ascending Yes]; NSArray * woeDescriptors = @ [woeDescriptor]; NSArray * sortedReturns = [topPlaces sortedArrayUsingDescriptors: woeDescriptors]; self.topPlaces = sortedReturns; // all data here, count 100 and the array will log in to NSLog to console (@ "here it is calculated% u", [self.topplaces count]);});}); // Repeat the following line to preserve selection among presentations. Self.clearSelectionOnViewWillAppear = No; }
The problem is that you make an asynchronous call to bring data (meaning That your array should be filled with data at some point in the future), but you will not reload your table view later: Calling reload data will: ... self.topplaces = sortedReturns; // All the data are here, the calculation is 100 and the array will log on to NSLog in the console (@ "here it has been calculated% u", [top top counting]); [Self.tableViewReloadData]; The // Assuming that the table view, 'Your outlet This will instruct to once again query your Detastro your Teblwu and eventually clear all your data (now) Top Location array
Further explanation: I saw in the comment of @ nerak99 that she is absolutely sure why the problem < Not defined with the code> reloadData . Well, let's use an example:
Imagine that you have a restaurant
you open in the morning at 06:00 and you see that you want to cook Nothing is found. So you can ask one of your men to go to the market for supplies (this is your asynchronous call ). At the same time you instruct the waitress to write in today's menu, so she writes ... well, nothing (this is your asking for the number of rows of table rows ) Now the man who returns to the market with 10 items is the next rational step to update his menu?
I hope this makes sense :) P>
Comments
Post a Comment