1
UIButtonをクリックしても表示されません。いくつかの図 私は間違って何をしているの?UIViewでUIButtonが応答しない
#import "MyView.h"
- (init){
self = [super init];
if(self)
[self createButton];
return self;
}
- (void) createButton{
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100,100,100,50)];
[button setTitle:@"Go" forState:UIControlStateNormal];
[button addTarget:self
`action:@selector(goAction)
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
- (void) goAction{
NSString *test = @"Some text";
}
MyViewController.m
- (id) init{
self = [super init];
if (self) {
MyView *myview = [[MyView alloc] init];
[self.view addSubview:myview];
}
return self;
}`
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
ViewController.m
#import "ViewController.h"
#import "MyViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MyViewController *myTestView = [[MyViewController alloc] init];
[self.view addSubview:myTestView.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
インライン 'オブジェクトC'を(あなたが別のものに1のViewControllerを追加する必要があり、なぜ私はまだ理解していないが)、それは動作します。この道の、 – user2754113
は、なぜあなたはプログラムで別の' UIViewController'(MyViewControllerを作成してください)?なぜMyViewをViewController.mに直接追加しないのですか? – schmidt9
MyViewをViewControllerに直接追加することは問題ありません。しかし、なぜMyViewControllerをViewControllerに追加しても機能しないのはわかりません! – user2754113