-1
显示自定义的UIView,我发现这个自定义的UIView here在故事板
现在,我想将它添加到myViewController。 我所做的一切:
在myViewController.h我:
#import <UIKit/UIKit.h>
#import "CJGGridView.h"
@class CJGGridView;
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet CJGGridView * theBoard;
@end
在故事板,我放在一个UIView,并将其定义为一个自定义类“CJGridView” 然后我连接到“theBoard” 。为了便于区分视图,我给它一个橙色背景色。
在myViewController.m我:
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [[CJGGridView alloc]initWithSquareSize:self.theBoard.frame.size.width/8];
}
现在,当我运行应用程序,我看到一个橙色的正方形,在左上角某种梯度。
但是,我没有看到我期望的电网。
我在做什么错在这里?
初始化u必须IBOutlet中theBoard和使用的alloc初始化 – vaibby
谢谢!将其更改为: theBoard = [theBoard initWithSquareSize:self.theBoard.frame.size.width/8]; – Sjakelien
那么,你的答案是不明确的。解决方案是初始化IBOutlet。正如问题所示,我已经选择了正确的课程。所以,如果你拿出那部分,我会打勾你 – Sjakelien