我想在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