2

Hello i'm trying to write a method that update a UIProgressbar !

The problem is that when both of values arrive fine to the method (NSLog display values) the division operation generate a bad_access when i run the application !!

I tried many messages from both value like intValue/inValue ...

Help me to solve this issue and how can I print values of 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];
     }
}
SJS
  • 2,647
  • 1
  • 17
  • 34
Bechir
  • 202
  • 2
  • 7

5 Answers5

0

try [currentOperationNumber intValue] in place of currentOperationNumber (or floatValue if setProgress expects a float). So....

int myProgress = [currentOperationNumber intValue] / [n intValue];
[downloadBar setProgress:myProgress];

Actually, isn't it a float value it expects in there?

Simon
  • 8,981
  • 2
  • 26
  • 32
0

NSNumber is an object wrapper for various primitive types, with what you are doing you are trying to divide a pointer by a pointer..

maybe try chaining the code to..

[downloadBar setProgress:([currentOperationNumer intValue] / [n intValue])];
steve
  • 1
0

You can print value by using following code

-(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];
     }
}
SJS
  • 2,647
  • 1
  • 17
  • 34
0

The best way to debug EXC_BAD_ACCESS:

  1. If you are not using XCode 4, then upgrade.
  2. In XCode 4, press CMD-I to run Instruments.
  3. Select the Zombies profile. (Background: EXC_BAD_ACCESS means you are sending a message to a deallocated object. Zombies turns on the zombie feature, so that objects with a retain count of 0 are not deallocated, but kept as a zombie. The NSZombie class raises an exception whenever a message is sent to it - thus it can be trapped, and identified the point of origin.)
  4. Run your app via Instruments. When it crashes, Instruments will be brought to the foreground with a pop-up callout that indicates the memory that was freed but accessed.
  5. You can click the little arrow in the lower right corner, this will give you that memory's alloc/retain/release history, and the code that performs the action. Click on the source column, it will take you to that line in the code.
Jay Imerman
  • 4,475
  • 6
  • 40
  • 55
  • XCode 3 was just too difficult to debug this way. 4 is worth the small hit you will have in learning curve on the new interface. – Jay Imerman Sep 23 '11 at 18:35
0

make it sure downloadBar.progress is a float and it's from 0.0 to 1.0 inclusive.

Please, try this:

float current = 0.0f; float count = 100.0f;

while (stuff..) { downloadBar.progress = current / count; }

it should work without problems.

Rafael Sanches
  • 1,823
  • 21
  • 28