Когда я использую салфетки жест на экране метку на экране она не обновить содержание и число стоп на 120, после того, как я объявляю:как обновить содержимое в UILabel
@property (weak, nonatomic) UILabel *label;
когда Я красть экран, то он появится сообщение об ошибке на Xcode,
Если кто-то может помочь мне решить эту проблему, я действительно ценю это
@interface ViewController()
{
double numOfSpeed;
}
@property (weak, nonatomic) UILabel *label;
@end
implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
numOfSpeed = 120;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 300, 100, 100)];
label.text =[NSString stringWithFormat:@"%.0f", numOfSpeed];
label.backgroundColor = UIColor.blueColor;
[self.view addSubview:label];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)];
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToControlTheSpeedOfRhythm:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[swipeLeft setNumberOfTouchesRequired:1];
[swipeRight setNumberOfTouchesRequired:1];
[swipeUp setNumberOfTouchesRequired:1];
[swipeDown setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:swipeLeft];
[self.view addGestureRecognizer:swipeUp];
[self.view addGestureRecognizer:swipeDown];
[self.view addGestureRecognizer:swipeRight];
}
- (void)swipeToControlTheSpeedOfRhythm:(UISwipeGestureRecognizer *)sender
{
NSLog(@"gesture respone");
if(sender.direction == UISwipeGestureRecognizerDirectionLeft)
{
numOfSpeed -= 10;
self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed];
NSLog(@"gesture Left respone");
}else if (sender.direction == UISwipeGestureRecognizerDirectionDown){
numOfSpeed -= 10;
self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed];
NSLog(@"gesture down respone");
}else if (sender.direction==UISwipeGestureRecognizerDirectionUp){
numOfSpeed += 10;
self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed];
NSLog(@"gesture up respone");
}else if(sender.direction==UISwipeGestureRecognizerDirectionRight){
numOfSpeed += 10;
self.label.text = [NSString stringWithFormat:@"%.0f", numOfSpeed];
NSLog(@"gesture right respone");
}
}
@end
Вы воссоздаете «этикетку»? – Larme
Пожалуйста, сообщите об ошибке. – danh