English 中文(简体)
将“国家措施”职能分为另一个类别,但代表团有错误
原标题:Trying to separate the NSURLConnection function into another class but get error on delegation

I want to create a MVC iphone app , a part of my app task is to get data from internet and I want to separate that part to a Model and here is what I ve written

//Connection.h
#import <Foundation/Foundation.h>


@interface Connection : NSObject 
{
    NSMutableData * rawData;
    BOOL ready;
}


-(id) initWithData;
-(BOOL) isDataReady;

@end


//Connection.m
#import "Connection.h"


@implementation Connection

-(id) initWithData
{
    self = [super init];
    if(self != nil)
    {
        ready = NO;
        rawData = [[NSMutableData alloc]init];
        NSString * urlString = [NSString stringWithString:@"http://www.google.com"];
        NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        [[NSURLConnection alloc] initWithRequest:[request delegate:self]];

        [rawData setLength:0];

        return self;
    }
    else {
        return nil;
    }
}
//I have implemented the connectiondidRecievedData and connectionDidFinishLoading also they are empty

但是,当我想要从我的控制者那里打上这一类别时,就会出现错误。

Connection * cn = [[Connection alloc] initWithData];

错误

2012-01-13 15:26:59.453 TestApp[20105:207] -[NSURLRequest delegate:]: unrecognized selector sent to instance 0x4e1f520 2012-01-13 15:26:59.455 TestApp[20105:207] * Terminating app due to uncaught exception NSInvalidArgumentException , reason: -[NSURLRequest delegate:]: unrecognized selector sent to instance 0x4e1f520 * Call stack at first throw: ( 0 CoreFoundation 0x00dd05a9 exceptionPreprocess + 185 1 libobjc.A.dylib
0x00f24313 objc_exception_throw + 44 2 CoreFoundation
0x00dd20bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3
CoreFoundation 0x00d41966 __forwarding
+ 966 4 CoreFoundation 0x00d41522 _CF_forwarding_prep_0 + 50 5 TestApp 0x0000257c -[Connection initWithData] + 339 6 TestApp
0x000020c3 -[TestAppViewController doTestB] + 122 7 UIKit
0x002c04fd -[UIApplication sendAction:to:from:forEvent:] + 119 8
UIKit 0x00350799 -[UIControl sendAction:to:forEvent:] + 67 9 UIKit
0x00352c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 10 UIKit 0x003517d8 -[UIControl touchesEnded:withEvent:] + 458 11 UIKit
0x002e4ded -[UIWindow _sendTouchesForEvent:] + 567 12 UIKit
0x002c5c37 -[UIApplication sendEvent:] + 447 13 UIKit
0x002caf2e _UIApplicationHandleEvent + 7576 14 GraphicsServices
0x01728992 PurpleEventCallback + 1550 15 CoreFoundation
0x00db1944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 16 CoreFoundation 0x00d11cf7 __CFRunLoopDoSource1 + 215 17 CoreFoundation 0x00d0ef83 __CFRunLoopRun + 979 18 CoreFoundation
0x00d0e840 CFRunLoopRunSpecific + 208 19 CoreFoundation
0x00d0e761 CFRunLoopRunInMode + 97 20 GraphicsServices
0x017271c4 GSEventRunModal + 217 21 GraphicsServices
0x01727289 GSEventRun + 115 22 UIKit
0x002cec93 UIApplicationMain + 1160 23 TestApp
0x00001e04 main + 102 24 TestApp
0x00001d95 start + 53 ) terminate called after throwing an instance of NSException

如何将国家措施与另一个类别分开?

最佳回答

您的法典有一处错误:

[[NSURLConnection alloc] initWithRequest:[request delegate:self]];

That should read:

[[NSURLConnection alloc] initWithRequest:request delegate:self];
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签