首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >arc4random测验崩溃

arc4random测验崩溃
EN

Stack Overflow用户
提问于 2011-03-28 15:54:58
回答 1查看 251关注 0票数 1

我对这一切都是新手。我已经浏览了论坛,但似乎找不到答案。我做了一个简单的测验,有20个问题(形成一个txt文件)

尝试让arc4random()代码随机选择问题。它可以工作,但在不同的时间崩溃的应用程序。有人能给我一些建议吗?谢谢。下面是我的一些代码:

代码:

代码语言:javascript
复制
// Go to the next question
int i;
int j;
NSInteger row = 0;

i = 20; i > 1;
{
j = arc4random()%i;

questionNumber = j + 1;

if(questionNumber == 1)
{
    row = questionNumber - 1;
}
else
{
    row = ((questionNumber - 1) * 6);
}}

// Set the question string, and set the buttons the the answers
NSString *selected = [theQuiz objectAtIndex:row];
NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%@", selected];
[answer1 setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
[answer2 setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
[answer3 setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
[answer4 setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];


// Set theQuestion label to the active question
theQuestion.text = activeQuestion;

// Start the timer for the countdown
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];

[selected release];
[activeQuestion release];

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-28 16:23:31

您可能不应该释放选定对象,因为objectAtIndex会返回自动释放的对象。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5456089

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档