发布于 11-26 18:00 字数 1790 浏览 1 评论 0原文

I am using 4 UILabels in one view.

-(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];
}

There is a one button for next Question.

-(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];        
}
}

当我点击下一个按钮时,我从文本文件中得到了下一个问题。
但问题是每次我点击下一个标签上的文本都会重叠。

What should i do for that??

谢谢..

I am using 4 UILabels in one view.

-(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];
}

There is a one button for next Question.

-(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];        
}
}

When i tap on next button i got the next question from my text file.
But the problem is every time i tap next the text on label overlaps.

What should i do for that??

Thanks..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪荡不羁2024-12-03 18:00:25

在执行[self setQuestion]之前尝试removeFromSuperview您的标签:

- (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];        
    }
}

Try to removeFromSuperview your labels before doing [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];        
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文