0

This is my code that convert a string to float

-(void) onUploadProgress:(id) sender valueString:(NSString *)valueString
{
    NSLog(@"Value String = %@", valueString);
    [progressbar setProgress:[valueString floatValue]];
}

This is the selector that call the function above

NSString *valueString = [NSString stringWithFormat:@"%f", ((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
[delegate performSelector:progressSelector withObject:(NSString*)valueString];

This code work on my iPad ios5 but when I tested on IOS 6 simulator , it throw me an exception [controller floatValue] unrecognized selector. I know it was caused by this but not sure why. It does have value in valueString variable.

Does anyone know why?

ThomasW
  • 16,981
  • 4
  • 79
  • 106
LittleFunny
  • 8,155
  • 15
  • 87
  • 198
  • 1
    What is the value of `progressSelector`? – ThomasW Dec 05 '12 at 01:31
  • Is the delegate meant to be calling this? and i dont see anything wrong, but the error sounds like a UIViewController is being put into its place, and they doesnt have a floatValue, so '[progressbar setProgress:[valueString floatValue]];' is the line getting the error, try making sure breakpoints are on in Xcode for "All Exceptions" and that could give you the line passing in the bad data. – Maximilian Litteral Dec 05 '12 at 01:36
  • I have put the breakpoint and error was located at the performSelector call. Funny thing is I checked with my mate phone with IOS 6, he managed to go through it without crashing. – LittleFunny Dec 05 '12 at 02:04
  • What prints out for the NSLog of valueString? (Presumably it's not a string in the failing case) – Hot Licks Dec 05 '12 at 02:14
  • 0.6323 something like that in string format. then convert to float – LittleFunny Dec 05 '12 at 02:24
  • Are you sure the exception is coming from the above floatValue invocation, and not from somewhere else? – Hot Licks Dec 05 '12 at 02:31
  • You say the exception message is `[controller floatValue] unrecognized selector`, but that's not a message that would be displayed. What is the precise message? – Hot Licks Dec 05 '12 at 02:32
  • GalleryDetailViewController floatValue]: unrecognized selector sent to instance 0x9d89940' *** First throw call stack: (0x1c75052 0x2051d0a 0x1c76ced 0x1bdbf00 0x1bdbce2 0xc36c 0x1c76e72 0x7acd 0x1370742 0x136ee94 0x136feb7 0x136ee4f 0x136efd5 0x12e68a4 0x23e6a75 0x24a76ce 0x23d1298 0x24a716b 0x23d1137 0x1c4997f 0x1bacb73 – LittleFunny Dec 05 '12 at 02:44
  • OK, you've got a GalleryDetailViewController object somewhere. And somehow it's having the "floatValue" method performed on it. (And see [here](http://stackoverflow.com/a/12268397/581994) to get the exception trace printed.) – Hot Licks Dec 05 '12 at 03:27
  • Hmm the second part of the code above is where the exception occurred. My iPad with IOS 5 works fine though.. only happen on the simulator at the moment. Try to update it to IOS 6 and see. – LittleFunny Dec 05 '12 at 03:31
  • What do you mean by "second part", and how do you know the exception is from there? Do you have an exception breakpoint set? – Hot Licks Dec 05 '12 at 03:44
  • Is this 'progressSelector' a NSString? I think it should be [delegate performSelector:@selector(progressSelector)...], isn't it? – Shinigamae Dec 05 '12 at 03:45
  • @Shinigamae - Presumably "progressSelector" is a selector variable set to `@selector(something:)`, where "something" is a method that eventually calls `onUploadProgress:valueString:`. But it would be nice if the OP showed us that code. – Hot Licks Dec 05 '12 at 03:48
  • Why do you have the cast of valueString to NSString in the last code line above if the value is declared as a NSString on the line immediately above that? Leads one to suspect that valueString is not really an NSString. – Hot Licks Dec 05 '12 at 13:01

1 Answers1

0

Try

[delegate performSelector:@selector(progressSelector) withObject:(NSString*)valueString];
Sam
  • 390
  • 1
  • 3
  • 15