繁体   English   中英

ChildView 不会调用我的委托方法!

[英]ChildView won't call my delegate method !

我有一个名为 controller: AskHome的父视图和一个名为 *record_audio* 的子视图。 AskHome 以模态方式显示recod_audio,我实现了一个委托协议,以便我可以将我在record_audio(子视图)中收到的NSNumber 变量发送回父视图(AskHome),但根本不调用委托方法:

所以 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,这意味着我的委托没有被调用,为什么? 有人有想法吗? 感谢你们:)

你在哪里设置record_audio的委托? 这很可能是它没有被设置的问题。 (调试思想并确保委托是一个有效的对象)

此外,使用名为“getWhatever”的委托方法也不是最佳做法。 您的设计模式可能存在缺陷,可能最适合 singleton。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM