0
我已經爲我的課程「HotRequest」設置了一個委託,但是在實現時遇到問題。我的課程代碼如下。有任何想法嗎?由於iPhone自定義代理問題
HotRequest.h
#import <Foundation/Foundation.h>
@protocol HotRequestDelegate;
@interface HotRequest : NSObject {
NSString *requestString;
id <HotRequestDelegate> delegate;
}
@property (nonatomic, retain) NSString *requestString;
@property (nonatomic, assign) id <HotRequestDelegate> delegate;
- (id)initWithRequestOptions:(NSDictionary*)dict;
@end
@protocol HotRequestDelegate <NSObject>
@required
- (void)requestComplete;
@end
HotRequest.m
#import "HotRequest.h"
@implementation HotRequest
@synthesize requestString, delegate;
- (id)initWithRequestOptions:(NSDictionary*)dict {
if ((self = [super init])) {
for (NSString *key in [dict allKeys]) {
requestString = [NSString stringWithFormat:@"%@&%@=%@", requestString, key, [dict objectForKey:key]];
}
NSLog(@"%@", requestString);
}
[delegate requestComplete];
return self;
}
@end
WelcomeViewController.h
#import <UIKit/UIKit.h>
#import "HotRequest.h"
@interface WelcomeViewController : UIViewController <HotRequestDelegate>{
HotRequest *myRequest;
}
@property (nonatomic,retain) HotRequest *myRequest;
@end
WelcomeViewController.m
#import "WelcomeViewController.h"
#import "HotRequest.h"
@implementation WelcomeViewController
@synthesize myRequest;
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *mydict = [[NSDictionary alloc] initWithObjectsAndKeys:@"2", @"1", @"4", @"3", nil];
myRequest = [[HotRequest alloc] initWithRequestOptions:mydict];
[[self myRequest] setDelegate:self];
}
- (void)requestComplete {
NSLog(@"request complete");
}
@end
不是零,實際上 - 未定義,這是更糟的,因爲它會導致崩潰。 – Echelon 2010-09-26 17:12:04
@Echelon:你錯了。在對象分配上,所有實例變量都被清零。 – 2010-09-26 17:20:59
我知道我必須做些什麼愚蠢的事情。非常感謝。 – Jack 2010-09-26 17:35:15