你好我正在编写一个更新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];
}
}发布于 2011-09-23 10:38:42
使用currentOperationNumber代替currentOperationNumber intValue (如果setProgress需要浮点数,则使用floatValue )。所以..。
int myProgress = [currentOperationNumber intValue] / [n intValue];
[downloadBar setProgress:myProgress];实际上,它不是在那里期望的浮点值吗?
发布于 2011-09-23 10:46:53
NSNumber是各种原语类型的对象包装器,您所做的是试图将指针除以指针。
也许试着把代码链接到..。
[downloadBar setProgress:([currentOperationNumer intValue] / [n intValue])];发布于 2011-09-23 10:53:07
您可以使用以下代码打印值
-(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];
}
}https://stackoverflow.com/questions/7527694
复制相似问题