我有一個叫做controller的父視圖:AskHome和一個名爲* record_audio *的子視圖。 AskHome顯示模態recod_audio,我實現了一個委託protocole,以便我可以發回到父視圖(AskHome)一個NSNumber變量,我在record_audio(子視圖)中收到,但委託方法根本不會被調用:ChildView不會調用我的委託方法!
所以chidView第一
* record_audio.h *
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
@protocol sendbackQuestionIdDelegate <NSObject>
@required
- (void)getIdDelegate:(NSNumber *)theQstId;
@end
@interface record_audio : UIViewController <AVAudioRecorderDelegate> {
//my stuff here
//......
id <sendbackQuestionIdDelegate> delegate;
}
@end
* record_audio.m *
#import "record_audio.h"
@implementation record_audio
@synthesize actSpinner, btnStart, btnPlay, btnCancel, btnValidate, delegate;
/* I do some stuff, upload the sound etc....
....
....
*/
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//i call the delgate, theAnswer is the string i received from the server as a response
[delegate getIdDelegate:(NSNumber *)[theAnswer intValue]];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//just dismiss this child view
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
父視圖:
AskHome.h
#import <UIKit/UIKit.h>
#import "record_audio.h"
@interface AskHome : UIViewController <sendbackQuestionIdDelegate>
{
//stuff here
}
//other stuff here
@end
AskHome.m
#import "AskHome.h"
#import "UIImage+Resize.h"
#import "record_audio.h"
@implementation AskHome
- (void)getIdDelegate:(NSNumber *)theQstId
{
NSLog(@"- ========= === <<<<<< The delegate method was called >>>>>>>>>> - ========= === ");
questionId = theQstId;
}
在控制檯我沒有上述的NSLog,這意味着我的委託不叫,爲什麼?有人有一個想法?謝謝你們:)
已切開;我忘了nick.delegate = self;當我打電話給childView – john 2011-04-28 21:59:38