私はここではほとんど初心者で、タイトルを書くことさえかなり大変でした...しかし、ここに行きます
私は自分のアプリにこれを実行させようとしています 1) ユーザーがボタンを押します 2) ボタンがプレスを int 値に変換します 3) 値が NStimer に渡され、int 値に達するまでタイマーがカウントされます (つまり 30 秒) int 値が 30 の場合 4) プログラムは画面上の画像を変更します
NStimer を起動し、変数ボタンを使用して画面を変更するようにしました。この値を手動で変更することで、タイマーが異なる時間後にオフになるように設定できます。
私ができないことは、ボタンを押して値が変更された後にタイマーを起動させることです。NSLog を使用すると、値が変化していることがわかりますが、NSTimer には影響しません。
少し長くなって申し訳ありませんが、コードは次のとおりです...何か助けていただければ幸いです...do whileループとifステートメントでこれを解決しようとして髪のほとんどを失ったので
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIImageView *theImage;
int imageCount;
int button;
button = 10;
}
@property (strong, nonatomic) IBOutlet UIImageView *theImage;
@property (strong, nonatomic) IBOutlet UIButton *press;
@end
//
// ViewController.m
// use ns timer to display an image
//
// Created by Clive Dancey on 19/02/2013.
// Copyright (c) 2013 Clive Dancey. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UILabel *label1;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:button
target:self
selector:@selector(animateFunction)
userInfo:nil
repeats:YES];
}
- (IBAction)press:(id)sender
{
button = 1;
}
- (void)animateFunction
{
NSLog(@"Timer heartbeat %i", button);
NSString *imageName = [NSString stringWithFormat:@"EZDecline.png"];
[_theImage setImage:[UIImage imageNamed:imageName]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end