gpt4 book ai didi

objective-c - 使用未声明的标识符

转载 作者:行者123 更新时间:2023-12-03 17:21:54 39 4
gpt4 key购买 nike

我是 Objective-C 编码新手,请耐心询问这是不是一个简单的问题我的头文件:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*) response;

@end

我的实现文件:

#import "AppDelegate.h"

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
NSMutableData *receivedData =[NSMutableData dataWithCapacity: 0];

// Create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"] cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];

// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [NSMutableData dataWithCapacity: 0];

// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!theConnection) {
// Release the receivedData object.
receivedData = nil;
// Inform the user that the connection failed.
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSMutableData *receivedData =[NSMutableData dataWithCapacity:0];


// This method is called when the server has determined that it
// has enough information to create the NSURLResponse object.

// It can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.

// receivedData is an instance variable declared elsewhere.
[receivedData setLength:0];
}
@end

当我在实现 appDelegate 中运行代码时,它会发出警告

Method definition for connection:didRecieveResponse :not found

在哪里

-(void)connection line it gives "use of undelcared identifier connection did u mean Collection".

最佳答案

您不需要声明该方法

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*) response; 

如果您在代码中使用 NSURLConnectionDataDelegate 协议(protocol),则在头文件中。只需在实现中添加协议(protocol)并使用该协议(protocol)中的方法即可。

关于objective-c - 使用未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22317536/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com