【发布时间】:2017-12-06 13:29:39
【问题描述】:
我发现了这个自定义 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”。为了便于区分 View,我给它一个橙色的背景色。
在 myViewController.m 我有:
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [[CJGGridView alloc]initWithSquareSize:self.theBoard.frame.size.width/8];
}
现在,当我运行应用程序时,我确实看到了一个橙色正方形,左上角有某种渐变。
但是,我没有看到预期的网格。
我在这里做错了什么?
【问题讨论】:
-
你有 iboutlet theBoard 并使用 alloc init
-
谢谢!将其更改为: theBoard = [theBoard initWithSquareSize:self.theBoard.frame.size.width/8];
-
嗯,你的答案是模棱两可的。解决方案是初始化 IBOutlet。如问题所示,我已经选择了正确的课程。所以,如果你把那部分去掉,我会打你的
标签: ios uiview storyboard subclass