- (void)viewDidLoad
{
[super viewDidLoad];
[VenueManager searchNear:@"Orlando"
onLoad:^(NSArray *objects) {
self.locationObjects = objects;
[self.tableView reloadData];
} onError:^(NSError *error) {
NSLog(@"%@", error);
}];
}
This code is in my viewDidLoad method of my UITableViewController class. It is the starting point for using RestKit to parse a JSON file from FourSquare. I was pulling my hair out because i couldn't get the objects to show up in my Table View until i put [self.tableView reloadData];. With out that call the app never even hit my - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
because after the block was done executing locationObjects would be nil.
Before when I was debugging it the self.locationsObjects = objects worked when i was in the block (i am very unfamiliar with blocks by the way). As soon as i was out of the block the debugger would say locationObjects was nil, even though it had said it had 30 objects just like objects did when i had a break point at the assignment statement.
Can some one help me understand what is going on here.
Additional info:
Right now everything is working, or appears to be working my table is populated with the objects request from the JSON document. Originally I was doing this exact same thing in a normal ViewController and trying to set the objects
from the block equal to locationObjects
. Then using a prepareForSegue
method i was trying to pass the locationObjects
to the tableViewController in the standard method i have learned from numerous tutorials. I would get a SIGBAT error. The thread would terminate because of an unrecognized selector sent to the table view controller. Through debugging i would find that locationObjects
could be nil in the prepareForSegue method. Here is the code from the viewController file.
Also I would get a warning here locationTableViewController.locationObjects = self.locationObjects;
saying something about assigning a pointer of type NSArray to strong NSArray, or something like that ( i have since changed a lot attempting to get the code working and deleted some storyboard assets, so i'm not 100% sure of the wording).
@implementation CoffeeShopViewController
@synthesize venueCountLable = _venueCountLable;
@synthesize locationObjects = _locationObjects;
- (void)viewDidLoad
{
[super viewDidLoad];
[VenueManager searchNear:@"Orlando"
onLoad:^(NSArray *objects) {
self.venueCountLable.text = [NSString stringWithFormat:@"%d", objects.count];
self.locationObjects = objects;
} onError:^(NSError *error) {
NSLog(@"%@", error);
}];
}
- (void)viewDidUnload
{
[self setVenueCountLable:nil];
[super viewDidUnload];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"locationTableSegue"])
{
LocationTableViewController *locationTableViewController = segue.destinationViewController;
locationTableViewController.locationObjects = self.locationObjects;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
@end