您好我正在尝试编写一个更新UIProgressbar的方法!
问题是当两个值都很好地到达方法时(NSLog显示值) 当我运行应用程序时,除法操作会生成bad_access !!
我尝试了很多来自两个值的消息,比如intValue / inValue ......
帮我解决这个问题,如何打印NSNumber的值
-(void)UpdateProgressbar:(NSNumber *)currentOperationNumer TotalOperationNumber:(NSNumber*)n
{
NSLog(@" operation : %i",currentOperationNumer);
NSLog(@" total : %i",n);
if (currentOperationNumer<=n)
{
[downloadBar setProgress:(currentOperationNumer/n )];
NSLog(@"progress !");
}
else
{
[self.view removeFromSuperview];
}
}
答案 0 :(得分:0)
尝试 [currentOperationNumber intValue] 代替 currentOperationNumber (如果setProgress需要浮点数,则使用floatValue)。所以....
int myProgress = [currentOperationNumber intValue] / [n intValue];
[downloadBar setProgress:myProgress];
实际上,它不是一个预期的浮动值吗?
答案 1 :(得分:0)
NSNumber是各种基本类型的对象包装器,你正在尝试用指针划分指针。
也许尝试将代码链接到..
[downloadBar setProgress:([currentOperationNumer intValue] / [n intValue])];
答案 2 :(得分:0)
您可以使用以下代码打印值
-(void)UpdateProgressbar:(NSNumber *)currentOperationNumer TotalOperationNumber:(NSNumber*)n
{
NSLog(@" operation : %@",currentOperationNumer);
NSLog(@" total : %@",n);
if (currentOperationNumer<=n)
{
[downloadBar setProgress:(currentOperationNumer/n )];
NSLog(@"progress !");
}
else
{
[self.view removeFromSuperview];
}
}
答案 3 :(得分:0)
调试EXC_BAD_ACCESS的最佳方法:
答案 4 :(得分:0)
确保downloadBar.progress是一个浮点数,它从0.0到1.0(含)。
请试试这个:
浮动电流= 0.0f; 浮点数= 100.0f;
while(stuff ..){ downloadBar.progress = current / count; }
它应该没有问题。