gpt4 book ai didi

ios - 使用委托(delegate)从 VC2 取消隐藏 VC1 中的按钮

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

我正在尝试使用辅助 VC 中的按钮取消隐藏 ViewControl 中的一些按钮。

在我的研究中,我发现我必须使用“委托(delegate)操作”。

我创建了两个名为 VC1 -> VC2 的类

enter image description here

VC1.h 包含:

#import <UIKit/UIKit.h>

@protocol CustomDelegate <NSObject>
-(void)hideUnhidebutton:(BOOL)value;
@end

@interface VC1 : NSObject <CustomDelegate>



@property (strong, nonatomic) IBOutlet UIButton *buttonToUnhide;

@end

在VC1.m中我实现了取消隐藏按钮的功能:

#import "VC1.h"

@interface VC1 ()

@end

@implementation VC1

-(void)hideUnhidebutton:(BOOL)value
{
[self.buttonToUnhide setHidden:value];

}

在此之后,我在 VC2.h 中添加了添加委托(delegate)变量作为属性

#import <UIKit/UIKit.h>
#import "VC1.h"


@interface VC2 : UIViewController

@property (nonatomic, strong) id<CustomDelegate> delegatePpty;

@end

最后我调用了VC2.m中的delegate函数

#import "VC2.h"


@interface VC2 ()

@end

@implementation VC2


-(void)someAction
{
[self.delegatePpty hideUnhidebutton:NO];//Call the delegate method to execute
}

没有问题,但当我尝试启动项目时,它在加载后崩溃并显示此问题:

enter image description here

这里是项目文件:

http://salvonostrato.com//ex/xcode5/TEST2.zip

我不知道下一步该做什么...请帮忙。

//已编辑

IT 不断崩溃显示:

enter image description here

最佳答案

您的 VC1 应该扩展 UIViewController。

@interface VC1 : UIViewController <CustomDelegate>

之后在界面生成器中再次建立连接。

关于ios - 使用委托(delegate)从 VC2 取消隐藏 VC1 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629681/

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