我创建了一个自定义委托方法来更新 ViewController 的背景颜色。我无法让委托方法做出响应。这是我的代码:
VASettingsView.h
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@class VASettingsView;
@protocol VASettingsViewDelegate <NSObject>
- (void)setNewBackgroundColour:(GLKVector4)newColour;
@end
@interface VASettingsView : UIView {
id <VASettingsViewDelegate> delegate;
}
@property (strong, nonatomic) IBOutlet UIButton *blackBackgroundButton;
@property (strong, nonatomic) IBOutlet UIButton *saveButton;
@property GLKVector4 backgroundColourSetting;
// Set delegate method
@property (nonatomic,weak)id delegate;
- (IBAction)blackButtonPressed:(id)sender;
- (IBAction)saveButtonPressed:(id)sender;
@end
VASettingsView.m
#import "VASettingsView.h"
@implementation VASettingsView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (IBAction)blackButtonPressed:(id)sender {
self.backgroundColourSetting = GLKVector4Make(0.0, 0.0, 0.0, 0.0);
}
- (IBAction)saveButtonPressed:(id)sender {
[delegate setNewBackgroundColour:self.backgroundColourSetting];
}
@end
VARendererViewController.h
@class VA_CASFrame;
@class VA_Character;
@class VA_Orbit_Camera;
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
#import <QuartzCore/QuartzCore.h>
#import "VASettingsView.h"
@interface VARendererViewController : GLKViewController <VASettingsViewDelegate>
{
// Code
}
VARendererViewController.m
ViewDidLoad
// Setup UIView to be delegate
VASettingsView *settingsView = [[VASettingsView alloc] init];
settingsView.delegate = self;
设置新背景颜色
- (void)setNewBackgroundColour:(GLKVector4)newColour{
self.backgroundColour = GLKVector4Make(newColour.x,
newColour.y,
newColour.z,
newColour.w
);
NSLog(@"STOP");
}
故事板:
我无法到达 setNewBackgroundColour 并且已经寻找了几个小时的答案。我看不到我做错了什么?
山姆