タイトルにあるように、UIViewをインポートしようとしていますが、動作させることができません。コードの最初のビットは、何もインポートせずに私がやろうとしていることを示しています。
@interface ViewController : UIViewController
{
UIView *firstUIView;
UIView *secondUIView;
}
@end
@implementation ViewController
-(void)firstUIView
{
firstUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
firstUIView.backgroundColor = [UIColor redColor];
[self.view addSubview:firstUIView];
}
-(void)secondUIView
{
secondUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
secondUIView.backgroundColor = [UIColor blueColor];
[self.view addSubview:secondUIView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self firstUIView];
[self secondUIView];
}
@end
次のビットでは同じ結果は得られませんが、私はそれを望んでいます-どこが間違っているのですか?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
firstUIViewExternal *firstUIView = [[firstUIViewExternal alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
secondUIViewExternal *secondUIView = [[secondUIViewExternal alloc] init];
[self.view insertSubview:firstUIView aboveSubview:self.view];
[self.view addSubview:secondUIView];
}
@end
firstUIViewExternalとsecondViewExternalのコードは同じですが、名前が次のように異なります。
-(void)secondUIView
{
secondUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
secondUIView.backgroundColor = [UIColor blueColor];
[self addSubview:secondUIView];
}
次に、上記のように-(void)viewDidLoadメソッドで使用されると宣言された#importedを使用してインポートされます。
インポートしたバージョンが機能しないのはなぜですか?
必要に応じて追加情報を提供します。ありがとう:-)
これは、UIViewのインポートで実現したいことですが、空白の白いものが表示されます。