ボタンをプログラムで作成し、ボタンタグを設定しました。私は1つのビューを作成し、ボタンがそのビューにサブビューです追加したiPhoneでボタンタグの複製を削除するにはどうすればよいですか?
:
ビューがロードを行いました。
-(void) viewDidLoad
{
self.answerSubview = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 320, 230)];
self.answerSubview.backgroundColor = [UIColor clearColor];
[self.view addSubview:answerSubview];
[self buttonCreation];
}
-(void) buttonCreation{
int x =100;
for(i = 0; i < 4; i++) {
UIButton *answerBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[answerBtn setFrame:CGRectMake(40, x, 260, 40)];
answerBtn.tag = ar[i];
[answerBtn setTitle:[answerList objectAtIndex:i] forState:UIControlStateNormal];
[self.answerSubview addSubview:answerBtn];
x = x+50;
}
}
と私は時間が終了すると、ボタンの特定のインデックスのための背景画像を設定したい、
-(void) timerFinished
{
for (UIView* view in [self.answerSubview subviews]) {
if([view isKindOfClass:[UIButton class]]){
UIButton *btn = (UIButton*)view;
NSLog(@"button value %d", btn.tag);
if(btn.tag == correctIndex)
{
[btn setBackgroundImage:[UIImage imageNamed:@"selected_correct_answer.png"] forState:UIControlStateNormal];
}
}
}
}
しかし、すべての時間は、タグ値をスタックに追加され、I 結果、今それはのように来て、ランダムに生成された数字を持っていると、ボタンタグにそれを設定します。
初めて、二時間、
0 0
1 1
3 3
2 2
3
1
2
0
(実際には私の予想される結果は3 1 2 0です)。
これまでのタグ値を削除して、一度に正しいタグ値を取得するにはどうすればよいですか。
私を助けてください。