我的实现文件中有一个错误,它一直在标记,我似乎无法修复。我已经注释掉了这个错误。我该如何解决这个错误?
#import "FilmSearchService.h"
@implementation FilmSearchService
@synthesize searchTerm;
@synthesize delegate;
@synthesize results;
-(void)main {
NSString *api_key = @"1234";
NSString *search_term = [searchTerm stringByAddingPercentEscapeUsingEncoding:NSASCIIStringEncoding]; // no visible @ interface for 'NSString' declares the selector 'stringByAddingPercentEscapeUsingEncoding'
NSString *url = [NSString stringWithFormat:@"http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=%@&q=%@", api_key, search_term];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
if (responseData != nil) {
NSError *error = nil;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
if (error) {
[delegate serviceFinished:self withError:YES];
} else {
results = (NSArray *) [json valueForKey:@"movies"];
[delegate serviceFinished:self withError:NO];
}
} else {
[delegate serviceFinished:self withError:YES];
}
}@end
filmsearchservice头文件:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ServiceDelegate.h"
@interface FilmSearchService : NSOperation
{
NSString *searchTerm;
id<ServiceDelegate> delegate;
NSArray *results;
}
@property (nonatomic, retain) NSString *searchTerm;
@property (nonatomic, retain) id<ServiceDelegate> delegate;
@property (nonatomic, retain) NSArray *results;
@end
我很抱歉,如果这是一个相对简单的修复问题,我对目标c很陌生,并感谢您的耐心等待。
谢谢。
答案 0 :(得分:3)
字符串方法是 stringByAddingPercentEscape * s * UsingEncoding not stringByAddingPercentEscapeUsingEncoding
答案 1 :(得分:0)
@ExitToShell是正确的。编译器显然不满意该字符串方法的拼写错误。这是&#34;书面示例&#34;:
NSString *search_term = [searchTerm stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
请注意,这并不是stringByAddingPercentEscapeUsingEncoding
,而不是字符串上的方法。
我认为您应该(a)将ExitToShell的答案标记为正确,并且(b)回到您提出的其他SO问题,并尝试提高您的录取率,使其优于&#39目前大约33%。