【问题标题】:No known instance method for selector 'receivedItemsJSON'选择器“receivedItemsJSON”没有已知的实例方法
【发布时间】:2014-03-05 22:40:20
【问题描述】:

我正在尝试构建一个测试 iOS 应用程序来解析来自 eBay 的 API 的 JSON,但我无法将响应转发给代理。我的 ItemCommunicator 实现中的 fetchingItemsFailedWithErrorreceivedItemsJSON 方法都收到警告 No known instance method for selector 错误。

XYZItemCommunicator.m:

#import "XYZItemCommunicator.h"
#import "XYZItemCommunicatorDelegate.h"
@implementation XYZItemCommunicator

- (void)searchItems
{
    NSString *urlAsString = [NSString stringWithFormat:@"http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=**************&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.12.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&sortOrder=PricePlusShippingLowest&paginationInput.entriesPerPage=7&outputSelector=AspectHistogram&itemFilter(0).name=Condition&itemFilter(0).value(0)=New&itemFilter(1).name=MaxPrice&itemFilter(1).value=450.00&itemFilter(1).paramName=Currency&itemFilter(1).paramValue=USD&itemFilter(2).name=MinPrice&itemFilter(2).value=350.00&itemFilter(2).paramName=Currency&itemFilter(2).paramValue=USD&itemFilter(3).name=ListingType&itemFilter(3).value=FixedPrice&keywords=Moto+x+16gb+unlocked"];
    NSURL *url = [[NSURL alloc] initWithString:urlAsString];
    NSLog(@"%@", urlAsString);

    [NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:url] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

        if (error) {
            [self.delegate fetchingItemsFailedWithError:error];
        } else {
            [self.delegate receivedItemsJSON:data];
        }
    }];
}

@end

XYZItemCommunicator.h:

#import <Foundation/Foundation.h>

@protocol ItemCommunicatorDelegate;

@interface XYZItemCommunicator : NSObject
@property (weak, nonatomic) id<ItemCommunicatorDelegate> delegate;

@end

XYZItemCommunicatorDelegate.h:

#import <Foundation/Foundation.h>

@protocol XYZItemCommunicatorDelegate <NSObject>
- (void)receivedItemsJSON:(NSData *)objectNotation;
- (void)fetchingItemsFailedWithError:(NSError *)error;
@end

【问题讨论】:

  • 你设置了什么对象(视图控制器)作为这个视图控制器的代理?无论您设置为该视图控制器的委托的任何对象都必须实现这两个协议方法。

标签: ios objective-c api delegates


【解决方案1】:

检查您的协议名称。你从

开始

ItemCommunicatorDelegate

改成

XYZItemCommunicatorDelegate

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 2014-09-16
    • 1970-01-01
    相关资源
    最近更新 更多