У меня есть метод в ViewController, чтобы нарисовать кнопку. В ViewController2 я хочу вызвать метод и вычеркнуть кнопку.Вызов метода из одного класса и используемый в другом классе
В ViewController.h
@interface ViewController : UIViewController
-(void)method;
@end
ViewController.m
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)method{
UIButton*Touch1= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[Touch1 addTarget:self action:@selector(TouchButton1:) forControlEvents:UIControlEventTouchUpInside];
[Touch1 setFrame:CGRectMake(50,50, 100, 100)];
Touch1.translatesAutoresizingMaskIntoConstraints = YES;
[Touch1 setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[Touch1 setExclusiveTouch:YES];
[self.view addSubview:Touch1];
NSLog(@"hi ");
}
-(void)TouchButton1:(UIButton*)sender{
NSLog(@"hi again");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Тогда я пытаюсь позвонить из ViewController2
- (void)viewDidLoad {
[super viewDidLoad];
ViewController * ViewCon = [[ViewController alloc]init];
[ViewCon method];
}
NSLog показывает правильный текст, но ни одна кнопка не была создана , В чем моя проблема?
Благодаря
плз добавить полную информацию, так что я могу вам помочь –