ios - 从 UIController 调用 UIView

标签 ios objective-c uiview

我正在尝试从我的 ViewController 调用 UIView FirstScreen。

但是我不知道该怎么做。

View Controller :

#import "ViewController.h"
#import "FirstScreen.h"

@interface ViewController ()
{
    FirstScreen *f; 
}

FirstScreen.m:

#import "FirstScreen.h"       
@implementation FirstScreen

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self didLoad];
    }
    return self;
}

-(void) didLoad{
    [self addLabel];
    [self addImageView];
}

最佳答案

@implementation FirstScreen

 - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    [self didLoad];
}
return self;
}

-(void) didLoad
{
 f = [[FirstScreen alloc] initWithFrame:CGRectMake(0, 0, self.view.size.width, self.view.size.height)];
[self.view addSubview:f];
}

关于ios - 从 UIController 调用 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30863933/

相关文章:

ios - 如果我们不在 init 方法中检查 "if (self)"会发生什么?

ios - Storyboard xcode 9.2 示例中需要恢复 id

ios - 底角不是圆的

ios - 更改 View 的边界不会更改它绘制的位置

iphone - 调整 UIView 的大小

iphone - [UILabel setImage :]: unrecognized selector sent to instance

ios - 将 Storyboard中的多个 View Controller 连接到 Xcode 6 中的代码

ios - 如何在 AVMutableComposition 中同时为多个视频层制作动画?

objective-c - Core Data 和 NSTableView 将内容显示为标题

ios - 为什么 Xcode 中的起始项目 "OpenGL Game"有 2 个立方体?