0
我已經創建了按鈕編程並設置按鈕標籤。如何刪除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];
}
}
}
}
但每一次,變量值被添加到堆棧中,我有隨機生成的數字,並將其設置爲按鈕標籤,所以現在它來了一樣, 結果:
第一次,第二次,
0 0
1 1
3 3
2 2
3
1
2
0
(其實我的預期結果是3 1 2 0)。
那麼我怎麼能刪除以前的標籤值,並在一次獲得正確的標籤值。
請幫我一把。