I am working with a UITableViewController. The method that fails is:
我正在使用UITableViewController。失败的方法是:
- (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的第一行引发的。
- (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
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;
}
}
2 个解决方案
#1
0
What happens if you change viewWillAppear like this:
如果您更改viewWillAppear会发生什么:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self testLoc];
}
#2
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.
哇,这次我肯定发现了自己的问题。刚摆脱[locationsRequest prepare];我肯定在某个地方看到了代码,但这告诉了我。
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.
EDIT原来这是一个内存分配错误。摆脱那条线并不是真正的解决方案。字符串被自动释放似乎有些问题。我在这里问了一个跟进问题。
#1
0
What happens if you change viewWillAppear like this:
如果您更改viewWillAppear会发生什么:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self testLoc];
}
#2
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.
哇,这次我肯定发现了自己的问题。刚摆脱[locationsRequest prepare];我肯定在某个地方看到了代码,但这告诉了我。
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.
EDIT原来这是一个内存分配错误。摆脱那条线并不是真正的解决方案。字符串被自动释放似乎有些问题。我在这里问了一个跟进问题。