[英]iPhone Objective-C: Exact same method call, working the first time, but getting “unrecognized selector” the second
I am working with a UITableViewController. 我正在使用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
. 测试结果表明,该异常在testLoc
的第一行中testLoc
。
- (NSDictionary *) getLocationsWithLatitude:(NSString *)latitude longitude:(NSString *)longitude;
All I do in the above method is make an HTTP request and return an NSDictionary. 我在上述方法中所做的只是发出一个HTTP请求并返回一个NSDictionary。
Below is my viewDidLoad (the first method call, which works) for the UITableViewController: 下面是我对UITableViewController的viewDidLoad(第一个方法调用,它起作用):
- (void)viewDidLoad {
self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self testLoc];
[super viewDidLoad];
}
And here is my viewWillAppear, which I get "unrecognized selector" from: 这是我的viewWillAppear,它从以下位置获得“无法识别的选择器”:
- (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: 这是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: 这是setUpTableArray:
- (void) setUpTableArray:(NSDictionary *)dict {
NSArray *array = [dict objectForKey:@"groups"];
if (array != nil) {
self.placesArray = array;
}
}
What happens if you change viewWillAppear like this: 如果您这样更改viewWillAppear会发生什么:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self testLoc];
}
Wow, I definitely found my own problem this time. 哇,这次我肯定找到了自己的问题。 Just get rid of [locationsRequest prepare];
只是摆脱[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 . 我在这里问了一个后续问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.