Bellow 我有一个委托系统,它隐藏一个按钮,然后将按钮保存在隐藏或不隐藏的任何位置NSUserDefault
。但是由于某种原因它不起作用,有人可以帮忙吗?
在这里,我有 levelComplete 代码... .h
#import <UIKit/UIKit.h>
#import "levelComplete.h"
#import "LevelSelector.h"
@interface levelComplete : UIViewController{
}
@property (nonatomic, strong) id<CustomDelegate> delegatePpty;
@end
.m
@implementation levelComplete
@synthesize delegatePpty;
-(void)someAction
{
[self.delegatePpty hideUnhidebutton:YES];//Call the delegate method to execute
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self someAction]; // Here I call my action
}
@end
在这里,我有 levelSelector 代码...
。H
@protocol CustomDelegate <NSObject>
-(void)hideUnhidebutton:(BOOL)value;
@end
#import <UIKit/UIKit.h>
#import "levelComplete.h"
#import "LevelSelector.h"
@interface LevelSelector : UIViewController <CustomDelegate>{
}
@property (nonatomic, strong) UIButton *level1;
@end
.m
@implementation LevelSelector
@synthesize level1;
-(void)hideUnhidebutton:(BOOL)value
{
[self.level1 setHidden:value];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSNumber numberWithBool:value] forKey:@"YourVariableKey"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL restoredBoolValue = [[defaults objectForKey:@"YourVariableKey"] boolValue];
}
@end
提前致谢 !!!
编辑
Thanks for all of your help I have now got the code to correctly function