【问题标题】:Displaying a custom UIView in a storyboard在故事板中显示自定义 UIView
【发布时间】: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


【解决方案1】:

你直接在viewdidload中初始化

- (void)viewDidLoad {
    [super viewDidLoad];
    theBoard = [CJGGridView initWithSquareSize:self.theBoard.frame.size.width/8];
}

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-04
    • 2018-09-19
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    相关资源
    最近更新 更多