I'm trying to use NSURLConnection
to "talk" to a server but when trying to use initWitRequest
I get this error:
我正在尝试使用NSURLConnection与服务器“对话”,但在尝试使用initWitRequest时出现此错误:
no known class method for selector 'initWithRequest:delegate:'
Is this not a proper usage of the method?
这不是该方法的正确用法吗?
NSURLConnection *conn = [NSURLConnection initWithRequest:theRequest delegate:self];
My Deployment Target is iOS 4.3. Under Base SDK it has listed Latest iOS (iOS 5.0)
. Could this be an issue?
我的部署目标是iOS 4.3。在Base SDK下,它已经列出了最新的iOS(iOS 5.0)。这可能是个问题吗?
2 个解决方案
#1
5
You're attempting to send -initWithRequest:delegate:
to the NSURLConnection
class
instead of an instance of that class.
您正在尝试将-initWithRequest:delegate:发送到NSURLConnection类而不是该类的实例。
By convention, any -init
method should be preceded by a message to alloc
on the class. In your example, conn
would be created like so:
按照惯例,任何-init方法都应该在class之前加上一条消息来分配。在您的示例中,conn将被创建如下:
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
#2
1
initWithRequest:delegate:
is an instance method, not a class method. You need to use connectionWithRequest:delegate:
, which is a class method:
initWithRequest:delegate:是一个实例方法,而不是类方法。您需要使用connectionWithRequest:delegate:,这是一个类方法:
NSURLConnection *conn = [NSURLConnection connectionWithRequest:theRequest delegate:self];
#1
5
You're attempting to send -initWithRequest:delegate:
to the NSURLConnection
class
instead of an instance of that class.
您正在尝试将-initWithRequest:delegate:发送到NSURLConnection类而不是该类的实例。
By convention, any -init
method should be preceded by a message to alloc
on the class. In your example, conn
would be created like so:
按照惯例,任何-init方法都应该在class之前加上一条消息来分配。在您的示例中,conn将被创建如下:
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
#2
1
initWithRequest:delegate:
is an instance method, not a class method. You need to use connectionWithRequest:delegate:
, which is a class method:
initWithRequest:delegate:是一个实例方法,而不是类方法。您需要使用connectionWithRequest:delegate:,这是一个类方法:
NSURLConnection *conn = [NSURLConnection connectionWithRequest:theRequest delegate:self];