我想創建一個具有視圖的不同類並在屏幕上調用該類。 當我運行應用程序時,視圖不會出現。如果我刪除該結構並在主文件上創建按鈕,它可以正常工作。當我把它放在不同的課堂上時,它不起作用。如何在不同的類中創建界面(UIView)並在屏幕上添加
MyView.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
viewController.m [...]
- (void)viewDidLoad
{
[super viewDidLoad];
viewHome * fncScreen;
UIView * homeScreen = [fncScreen myHome];
[self.view addSubview:homeScreen];
}
由於
其中的
這就是我寫的:)順便說一句,他可能不會需要你的代碼片段的最後一行,實際上它甚至會拋出一個錯誤。 ARC是過去兩年的默認選項! – 2013-02-26 15:20:10
@IvanKovacevic ...大聲笑... – yunas 2013-02-26 16:03:46