views:

83

answers:

2

I am working with a UITableViewController. The method that fails is:

- (void) testLoc {
    self.dictionary = [self.delegate getLocationsWithLatitude:@"0.0" longitude:@"0.0"]; //HERE
    [self setUpTableArray:dictionary]; 
}

Test results have shown that the exception is thrown in the first line of testLoc.

- (NSDictionary *) getLocationsWithLatitude:(NSString *)latitude longitude:(NSString *)longitude;

All I do in the above method is make an HTTP request and return an NSDictionary.

Below is my viewDidLoad (the first method call, which works) for the UITableViewController:

- (void)viewDidLoad {
    self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [self testLoc];
    [super viewDidLoad];
}

And here is my viewWillAppear, which I get "unrecognized selector" from:

- (void)viewWillAppear:(BOOL)animated {
    self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [self testLoc];
    [super viewWillAppear:animated];
}

Here is the error that I am getting:

-[NSCFString key]: unrecognized selector sent to instance 0x141770

The reason I am doing this is because I have a table view that I want to update every time I tab back to it with a tab bar.

This is for the first real app that I am building, and I would really appreciate any kind of insight. Thanks!!

UPDATE

Here is getLocationsWithLatitude:

- (NSDictionary *) getLocationsWithLatitude:(NSString *)latitude longitude:(NSString *)longitude {
OAMutableURLRequest *locationsRequest = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://somerequesturl"] 
                                                                        consumer:self.globals.consumer 
                                                                           token:self.globals.requestToken 
                                                                           realm:nil signatureProvider:nil];
[locationsRequest setHTTPMethod:@"GET"];

[locationsRequest setParameters:[NSArray arrayWithObjects:
                                 [OARequestParameter requestParameter:@"geolat" value:latitude],
                                 [OARequestParameter requestParameter:@"geolong" value:longitude],
                                 nil]];

[locationsRequest prepare];
NSData *locationsData = [NSURLConnection sendSynchronousRequest:locationsRequest returningResponse:nil error:nil];
NSString *locationsString = [[[NSString alloc] initWithData:locationsData encoding:NSUTF8StringEncoding] autorelease];

    [locationsRequest release];
    SBJSON *jsonParser = [SBJSON new];
    NSError *error = nil;
    return [jsonParser objectWithString:locationsString error:&error]; 
}

Here is setUpTableArray:

- (void) setUpTableArray:(NSDictionary *)dict {

    NSArray *array = [dict objectForKey:@"groups"];
    if (array != nil) {
        self.placesArray = array;
    }
}
A: 

What happens if you change viewWillAppear like this:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self testLoc];
}
BarrettJ
Still causes the same problem. Argh, I can't tell what's wrong.
ayanonagon
A: 

Wow, I definitely found my own problem this time. Just get rid of [locationsRequest prepare]; I definitely saw code somewhere that has that, but this tells me otherwise.

EDIT Turns out this was a memory-memory allocation error. Getting rid of that line wasn't the actual fix. It seems to be some problem with a string being auto-released. I asked a follow up question here.

ayanonagon
Good you figured that out... Well if an open source framework which i don't use myself is causing the problem, it's hard for me to guess :p
Yuji
Haha yes. I guess I shouldn't assume that all of these tutorials online are perfect. Thanks for your help! :)
ayanonagon
I keep on finding that I had other bugs. A HUGE bug I had, which that I had OAConsumer on autorelease, which made my consumer key and secret set to random things like UIImages... Man, going from garbage collection to memory management is tough.
ayanonagon