我想在iOS中开始使用UI编程,我的第一个移动应用程序主要使用故事板,所以我希望我的UI更加灵活。我一直在线上跟随一对夫妇的教程,我仍然无法让我的视图和子视图在运行Xcode模拟器时显示出来。我用一个viewController创建了一个单一视图应用程序。这是我的“ViewController.h”和“ViewController.m”文件中的代码。我在这里做错了什么人?我的模拟器没有显示任何内容,根据我一直遵循的教程应该是。以编程方式创建视图iPhone编程
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property(strong, nonatomic) UILabel *label1;
@property(strong, nonatomic) UIButton *someButton;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Create the label
self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 25)];
self.label1.text = @"I am a label";
// Create the button
self.someButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.someButton.frame = CGRectMake(10, 50, 100, 37);
[self.someButton setTitle:@"Example Button" forState:UIControlStateNormal];
// Add them to the main view
[self.view addSubview:self.label1];
[self.view addSubview:self.someButton];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
你有没有指定在故事板'ViewController'类控制器? –
你是什么意思? – AyBayBay
@Virussmca是的我做过 – AyBayBay