【发布时间】:2014-10-10 15:31:09
【问题描述】:
由于某种原因,我不断收到“隐式转换失去整数精度”错误,它说它将它从 unsigned long 更改为 int(在我尝试随机化问题的部分中)。我对编程很陌生,我不知道如何解决这个问题。有人可以帮忙吗?
这是我的代码:
@interface ViewController ()
{
NSArray *questionArray;
UILabel *questionLabel;
}
@end
2) ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
//create question array
questionArray = [NSArray arrayWithObjects:@"Question 1?", @"Question 2?", @"Question 3?", @"Question 4?", nil];
//random a question
int lowerBound = 0;
int upperBound = [questionArray count] - 1;
int randomValue = lowerBound + arc4random() % (upperBound - lowerBound);
//create UILabel
questionLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 20)];
[questionLabel setTextAlignment:NSTextAlignmentCenter];
[questionLabel setText:[questionArray objectAtIndex:randomValue]];
[self.view addSubview:questionLabel];
//create next button
nextButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 150, 320, 100)];
[nextButton setTitle:@"Next Question" forState:UIControlStateNormal];
[nextButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[nextButton addTarget:self action:@selector(nextQuestionButtonSelected) forControlEvents:UIControlEventTouchUpInside];
}
【问题讨论】:
标签: ios objective-c int implicit-conversion nsinteger