本文介绍了使用委托从VC2中取消隐藏VC1中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图用一个次级VC中的按钮取消隐藏ViewControl中的某些按钮。I am trying to Unhide some buttons in a ViewControl using a button in a secondary VC.在我的研究中,我发现我必须使用委托动作On my researches I found out that I have to use a "Delegation action".我创建了两个名为VC1的类 - > VC2 I have created two classes named VC1 -> VC2 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中我已经实现了取消隐藏的功能按钮:in VC1.m I have implemented the function that unhide the button:#import "VC1.h"@interface VC1 ()@end@implementation VC1-(void)hideUnhidebutton:(BOOL)value{ [self.buttonToUnhide setHidden:value];}此后,我添加了在VC2中添加委托变量作为属性.h After this I have added add delegate variable as property in VC2.h #import <UIKit/UIKit.h>#import "VC1.h"@interface VC2 : UIViewController@property (nonatomic, strong) id<CustomDelegate> delegatePpty;@end最后我在VC2中调用了委托函数.m And in the end I called the delegate function in VC2.m#import "VC2.h"@interface VC2 ()@end@implementation VC2-(void)someAction{ [self.delegatePpty hideUnhidebutton:NO];//Call the delegate method to execute}有没有问题,但是当我尝试启动项目时,它在加载后显示以下问题:there are no issue but when I try to launch the project it just crash after loading showing this issue: 这里的项目文件: http://salvonostrato.com//ex/xcode5/TEST2.zip 我不知道下一步该怎么办... 请帮忙。I am not sure what to do next...please help. // EDITED //EDITED IT不断崩溃: 推荐答案我会改变一些事情我会分享这个。请检查Hi i review your code & i'll changes some things. i'll share this one . please check itReplace @interface VC1 : UIViewController <CustomDelegate> instead of @interface VC1 : NSObject <CustomDelegate>在故事板中添加导航控制器,如下图所示 And add a navigation controller in story board like below image现在它的运行完美:) 这篇关于使用委托从VC2中取消隐藏VC1中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 08:18