我会快速解决这个问题:我有一个适用于 iPhone OS 3.1.2 的应用程序,可以减少分数。我有4个网点:
- oTop 和 oBottom:两个 UITextField,分别代表 originalTop 和 originalBottom。
- rTop和rBottom:两个UILabel,分别代表reduceTop和reduceBottom。
这是我使用的代码:
-(IBAction)减少{
int numerator = [[oTop text] intValue];
int denominator = [[oBottom text] intValue];
if (denominator > 0) {
NSMutableArray *factors1 = [[NSMutableArray alloc] init];
NSMutableArray *factors2 = [[NSMutableArray alloc] init];
int factors1length;
int factors2length;
for (int i = 1; i < ceil(sqrt(numerator)); i ++) {
[factors1 addObject:[NSString stringWithFormat:@"%@", i]];
if (round(numerator / i) != numerator / i) {
[factors1 removeLastObject];
} else {
factors1length ++;
}
}
for (int i = factors1length; i <= 0; i --) {
[factors1 addObject:[NSString stringWithFormat:@"%@", (numerator / [[factors1 objectAtIndex:i] intValue])]];
} //End get numerator factors
for (int i = 1; i < ceil(sqrt(denominator)); i ++) {
[factors2 addObject:[NSString stringWithFormat:@"%@", i]];
if (round(denominator / i) != denominator / i) {
[factors2 removeLastObject];
} else {
factors2length ++;
}
}
for (int i = factors2length; i <= 0; i --) {
[factors2 addObject:[NSString stringWithFormat:@"%@", (denominator / [[factors2 objectAtIndex:i] intValue])]];
} //End get denominator factors
}
}
对杂散线感到抱歉。无论如何,有人可以告诉我发生了什么事吗?当我启动时,在两个文本字段中输入一个大于 0 的数字,然后按“减少”按钮,应用程序崩溃。请帮忙,
嗨盖伊
编辑:将第一个和第三个 for 循环从 (int i = 0 更改为 (int i = 1.