1

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;
    }
}
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
Ayaka Nonaka
  • 856
  • 1
  • 10
  • 22
  • It would help if you show us the actual exception – freespace Jul 15 '10 at 15:31
  • @freespace I just updated my question with the error. Thanks! – Ayaka Nonaka Jul 15 '10 at 15:34
  • 1
    You need to post the code of `setUpTableArray` and `getLocationWithLatitute:Longitute:`. – Yuji Jul 15 '10 at 15:44
  • @Yuji setUpTableArray and getLocationWithLatitude are now posted. – Ayaka Nonaka Jul 15 '10 at 15:57
  • Ugh, the problem might be inside `SBJSON`... Could you check what's returned by `jsonParser`? Is it really returning a dictionary? – Yuji Jul 15 '10 at 16:01
  • Also, when you see the `unrecognized selector` error, the stack trace should also be shown there, i.e. which sequence of method calls triggered the error. That contains the info where the error occurred. The error means that you called a method `key` on an `NSString`. That might have occurred because `NSDictionary` or `NSArray` contained an object whose class is different from what you expected. – Yuji Jul 15 '10 at 16:05
  • Gah, I just found my own error. Such a stupid little mistake too. – Ayaka Nonaka Jul 15 '10 at 16:10
  • Also, +1 for asking me to post getLocationWIthLatitude. In my mind, I was so sure everything was fine in that method. – Ayaka Nonaka Jul 15 '10 at 16:27
  • Nevermind, locationsString is auto-released. – Ayaka Nonaka Jul 15 '10 at 16:52

2 Answers2

0

What happens if you change viewWillAppear like this:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self testLoc];
}
BarrettJ
  • 3,431
  • 2
  • 29
  • 26
0

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.

Community
  • 1
  • 1
Ayaka Nonaka
  • 856
  • 1
  • 10
  • 22
  • 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 Jul 15 '10 at 18:36
  • Haha yes. I guess I shouldn't assume that all of these tutorials online are perfect. Thanks for your help! :) – Ayaka Nonaka Jul 15 '10 at 18:44
  • 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. – Ayaka Nonaka Jul 16 '10 at 18:04