Я развиваю змеиную игру, и для этого я создал 3 класса: Player, Control и Grid. На мой вопрос, я хотел бы создать кнопку воспроизведения программно, в которой функция создания кнопки в классе Control и эта функция вызывается в ViewController.mСоздайте программную кнопку программно в отдельном классе
В ViewController.h я определил
@property (nonatomic, strong) Control *control; //object of Control class
@property (weak) IBOutlet UIButton *button;
В ViewController.m:
self.control = [[Control alloc] init];
[control createButton:_viewC Button:_button]; //_viewC is the view where the button will be shown
[_button addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside]; //since play method in ViewController.m
В классе управления:
-(void)createButton:(UIView*)view Button:(UIButton*)button
{
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"Play" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal ];
button.backgroundColor = [UIColor whiteColor];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
button.layer.cornerRadius = 10;
button.frame = CGRectMake(35, 30, 70, 40);
[view addSubview:button];
}
Проблема в том, что я запускаю игру и нажимаю кнопку, никаких действий не происходит! Может кто-то помочь мне с этим. Благодаря
У меня ошибка «UIApplicationMain (argc, argv, nil, NSStringFromClass ([Класс AppDelegate])); – Nasser
Вы добавили - (void) createButton: (UIView *) view Кнопка: (UIButton *) кнопка Селектор: (SEL) селектор; в .h (файл заголовка)? – alicooke
Да, я добавил, что – Nasser