gpt4 book ai didi

objective-c - 委托(delegate)未调用方法

转载 作者:行者123 更新时间:2023-11-28 22:47:57 25 4
gpt4 key购买 nike

所以我有一个问题。有人能告诉我这行调用(协议(protocol))方法的代码的问题吗

 [self.delegate poplogin];

poplogin 是方法名称,由于某种原因它不起作用。它没有调用方法 poplogin

供引用:

@property(nonatomic,retain) id<loginAuthDelegate> delegate;

所以让我解释一下这个案例

假设我有一个类 abc.h

@protocol loginAuthDelegate <NSObject>
-(void)poplogin;
@end

界面后

@property(nonatomic,retain) id<loginAuthDelegate> delegate;

in .m i am just calling the Delegate and @synthesize it
[self.delegate poplogin];

not i have another files
let say def.h
i am importing the Class abc.h
@interface def : UIViewController<loginAuthDelegate>



def.m
-(void)poplogin
{
NSLog(@"Delegate doesn't respond to here");
vmpaSecureLogin *ivc = [[vmpaSecureLogin alloc] init];
ivc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:ivc animated:YES];
}

最佳答案

这可能是因为 self.delegatenil

您可能忘记了将您的对象的委托(delegate)影响到您在其中实现了委托(delegate)方法的其他对象,例如您的 ViewController 或其他东西。

关于objective-c - 委托(delegate)未调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12713055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com