我想创建一个具有视图的不同类并在屏幕上调用该类。当我运行应用程序时,视图不会出现。如果我删除该结构并在主文件上创建按钮,它工作正常。当我把它放在不同的班级时,它不起作用。
我的视图.h
#import <UIKit/UIKit.h>
@interface viewHome : UIViewController
-(UIView*) myHome;
@end
MyView.m(为测试创建一个按钮)
#import "viewHome.h"
@implementation viewHome
-(UIView*) myHome {
UIView * myScreen = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
myScreen.backgroundColor = [UIColor whiteColor];
UIButton * myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(100,100,100,44);
[myButton setTitle:@"Login" forState:UIControlStateNormal];
[myScreen addSubview:myButton];
return myScreen;
}
@end
视图控制器.m [...]
- (void)viewDidLoad
{
[super viewDidLoad];
viewHome * fncScreen;
UIView * homeScreen = [fncScreen myHome];
[self.view addSubview:homeScreen];
}
谢谢