1
UIButton in meiner Ansicht reagiert nicht, wenn ich darauf klicke. Irgendeine Zahl aus was mache ich falsch? Hier ist meine gesamte Code:UIButton reagiert nicht in UIView
MyView.h
@interface Myview : UIView
@end
MyView.m
#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
inline 'Objekt C', – user2754113
Warum erstellen Sie programmatisch eine andere' UIViewController' (MyViewController) Warum nicht 'MyView' direkt in ViewController.m hinzufügen? – schmidt9
Es wäre kein Problem, MyView direkt zu ViewController hinzuzufügen. Aber ich verstehe nicht, warum es nicht funktioniert, wenn ich MyViewController in ViewController einfüge! – user2754113