自定义视图未显示

时间:2015-07-09 08:16:34

标签: ios objective-c

我正在为我的项目使用MVC模型技术。如果我直接在custom view文件中viewDidLoad编写viewController的代码,则会出现view。但是,如果我要为视图创建另一个类,那么它不会显示标签。

代码:

ViewController.m:

- (void)viewDidLoad{

[homepagVar homeView:self.view]; /* homepagVar is the variable of homePage class and homeView is method of homePage class */

[super viewDidLoad];

}

主页类:

-(UIView*)homeView:(UIView*)Hview
{

    toplabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 18, Hview.frame.size.width,30)];

    toplabel.text=@"NexgHomes.com";
    toplabel.textColor=[UIColor whiteColor];
    toplabel.textAlignment=NSTextAlignmentCenter;
    toplabel.font=[UIFont fontWithName:@"Helvetica"size:18];
    toplabel.backgroundColor=[UIColor blueColor];
    [Hview addSubview:toplabel];
    return Hview;
}

没有以这种方式显示标签。为什么?

1 个答案:

答案 0 :(得分:0)

尝试以下代码

- (void)viewDidLoad{

  [super viewDidLoad];
  [homepagVar homeView:self.view]; 
  [self.view addSubview:homepagVar];

}
相关问题