我在一个视图中使用了4个UILabel。
-(void)setQuestion{
Challenge = [[[UILabel alloc] initWithFrame:CGRectMake(16, 70, 294, 150)] autorelease];
Challenge.text = challengetext ;
Challenge.lineBreakMode = UILineBreakModeWordWrap;
Challenge.backgroundColor = [UIColor clearColor];
[self.view addSubview:Challenge];
Question = [[[UILabel alloc] initWithFrame:CGRectMake(16, 100 + Challenge.frame.size.height, 294, 150)] autorelease];
Question.text = activeQuestion ;
Question.lineBreakMode = UILineBreakModeWordWrap;
Question.backgroundColor = [UIColor clearColor];
[self.view addSubview:Question];
Answer = [[[UILabel alloc] initWithFrame:CGRectMake(16, 130 + Challenge.frame.size.height + Question.frame.size.height , 294, 150)] autorelease];
Answer.text = [theQuiz objectAtIndex:row+1] ;
Answer.lineBreakMode = UILineBreakModeWordWrap;
Answer.backgroundColor = [UIColor clearColor];
[self.view addSubview:Answer];
Description = [[[UILabel alloc] initWithFrame:CGRectMake(16, 160 + Challenge.frame.size.height + Question.frame.size.height + Answer.frame.size.height , 294, 150)] autorelease];
Description.text = [theQuiz objectAtIndex:row+2] ;
Description.lineBreakMode = UILineBreakModeWordWrap;
Description.backgroundColor = [UIColor clearColor];
[self.view addSubview:Description];
}
下一个问题有一个按钮。
-(IBAction)next{
[scrollview scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
NSInteger endOfQuiz = [theQuiz count];
//[Challenge setHidden:YES];
if((((questionNumber - 1) * 4) + 4) == endOfQuiz)
{
restartGame = YES;
}else
{
[self setQuestion];
}
}
当我点击下一个按钮时,我从我的文本文件中得到了下一个问题 但问题是我每次点击标签重叠上的文字。
我该怎么做?
谢谢..
答案 0 :(得分:0)
在执行removeFromSuperview
之前尝试[self setQuestion]
您的标签:
- (IBAction)next {
[scrollview scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
NSInteger endOfQuiz = [theQuiz count];
//[Challenge setHidden:YES];
if((((questionNumber - 1) * 4) + 4) == endOfQuiz) {
restartGame = YES;
} else {
[Challenge removeFromSuperview];
[Question removeFromSuperview];
[Answer removeFromSuperview];
[Description removeFromSuperview];
[self setQuestion];
}
}