0

ユーザーがボタンを押して、タップごとに多数のテキスト応答を取得できるアプリを作成しました。10 回の応答の後、ボタンは言うことがなくなったので、ユーザーがタップしてボタン メソッドを再度実行できるように、リセット ボタンを配置しました。この時点で、リセットを行う方法を見つけるのに苦労しています。

@implementation ViewController
@synthesize billLabel, topLabel, bill;

 - (void)viewDidLoad
{
[super viewDidLoad];

[bill setHidden:YES];

}

 - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)button:(id)sender
{
[bill setHidden:NO];
static int counter;

if (counter == 0)
{
    billLabel.text = @"text";
}
else if (counter == 1)
{
    billLabel.text = @"text2";
}
else if (counter == 2)
{
    billLabel.text = @"text3";
}
else if (counter == 3)
{
    billLabel.text = @"text4";
}
else if (counter == 4)
{
    billLabel.text = @"text5";
}
else if (counter == 5)
{
    billLabel.text = @"text6";
}
else if (counter == 6)
{
    billLabel.text = @"text7";
}
else if (counter == 7)
{
    billLabel.text = @"text8";
}
else if (counter == 8)
{
    billLabel.text = @"text9";
}
else if (counter == 9)
{
    billLabel.text = @"text10";
}
else if (counter == 10)
{
    billLabel.text = nil;
}

counter += 1;

}

- (IBAction)reset:(id)sender
{

}

@end
4

1 に答える 1

0

あなたの質問は少しわかりにくいですが、私はあなたが何をすべきか知っていると思います. int counter最初にクラスレベル変数を作成します。その時点で必ず 0 として宣言してください。次に、リセット メソッドでこのコードを使用するだけで、

カウンター = 0;

その後、ボタンを無効にすることもできますが、それはあなた次第です。

于 2012-10-04T19:17:03.020 に答える