0

我的实现文件中有一个错误,它一直在标记,我似乎无法修复。我已经注释掉了错误。我该如何解决这个错误?

#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

电影搜索服务头文件:

#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 很陌生,希望您能耐心等待。

谢谢你。

4

2 回答 2

3

字符串方法是stringByAddingPercentEscape *s* UsingEncoding不是stringByAddingPercentEscapeUsingEncoding

于 2013-10-20T22:00:34.157 回答
0

@ExitToShell 是正确的。编译器显然对该字符串方法的拼写错误感到不满。这是“书面示例”:

NSString *search_term = [searchTerm stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

请注意,它没有说stringByAddingPercentEscapeUsingEncoding,这不是字符串上的方法。

我认为您应该(a)将 ExitToShell 的答案标记为正确,并且(b)回到您提出的其他 SO 问题,并尝试将您的接受率提高到比目前大约 33% 更好。

于 2013-10-20T23:03:38.173 回答