[英]iPhone Objective-C: Exact same method call, working the first time, but getting “unrecognized selector” the second
我正在使用UITableViewController。 失敗的方法是:
- (void) testLoc {
self.dictionary = [self.delegate getLocationsWithLatitude:@"0.0" longitude:@"0.0"]; //HERE
[self setUpTableArray:dictionary];
}
測試結果表明,該異常在testLoc
的第一行中testLoc
。
- (NSDictionary *) getLocationsWithLatitude:(NSString *)latitude longitude:(NSString *)longitude;
我在上述方法中所做的只是發出一個HTTP請求並返回一個NSDictionary。
下面是我對UITableViewController的viewDidLoad(第一個方法調用,它起作用):
- (void)viewDidLoad {
self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self testLoc];
[super viewDidLoad];
}
這是我的viewWillAppear,它從以下位置獲得“無法識別的選擇器”:
- (void)viewWillAppear:(BOOL)animated {
self.delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self testLoc];
[super viewWillAppear:animated];
}
這是我得到的錯誤:
-[NSCFString key]: unrecognized selector sent to instance 0x141770
我這樣做的原因是因為我有一個表格視圖,每次我使用標簽欄將其切換回該表格視圖時,都希望對其進行更新。
這是我正在構建的第一個真實應用程序,非常感謝任何見解。 謝謝!!
更新
這是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];
}
這是setUpTableArray:
- (void) setUpTableArray:(NSDictionary *)dict {
NSArray *array = [dict objectForKey:@"groups"];
if (array != nil) {
self.placesArray = array;
}
}
如果您這樣更改viewWillAppear會發生什么:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self testLoc];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.