【问题标题】:Subclass viewController in storyboard and programmatically change UI from subclass故事板中的子类 viewController 并以编程方式从子类更改 UI
【发布时间】:2014-04-11 11:11:30
【问题描述】:

我基本上想要做的是有一个带有 navController 和几个以编程方式设置的视图的故事板 - 或者至少有以编程方式添加的子视图。所以我设置了一个示例工作区,我有一个 navController 和 2 个 viewController,它们根据按下的按钮来推送。

故事板如下:

如您所见,底部的 viewController 的类设置为 CVViewController。在CVViewController,我有我的viewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIView *redColor = [[UIView alloc] initWithFrame:self.view.window.frame];
    redColor.backgroundColor = [UIColor redColor];

    [self.view addSubview:redColor];
}

但是当我在模拟器上进入这个视图时,应该没有红色背景(因为我以编程方式添加了它)。

所以我不确定我哪里出错了。我基本上只是希望能够从自定义类以编程方式配置故事板视图控制器

【问题讨论】:

    标签: ios objective-c uiviewcontroller storyboard


    【解决方案1】:

    改变这个:

    UIView *redColor = [[UIView alloc] initWithFrame:self.view.window.frame];
    

    到这里:

    UIView *redColor = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多