I am using a NSString output of a NSMutableArray
to put as text for a UIAlertView
, to appear as the default text.
I find that I have to recreate an NSString
from the NSString
coming from the dictionary, otherwise it creates an 'NSInvalidArgumentException'.
Specifically, when I call:
NSMutableArray *serverResponseNumbers;
...
UIAlertView *alertviewmod=[[UIAlertView alloc] initWithTitle:@"Modify" message:nil delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Confirm",nil];
[alertviewmod setDelegate:self];
alertviewmod.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; //two text fields
[alertviewmod textFieldAtIndex:0].keyboardType=UIKeyboardTypeNumberPad;
NSString *nsRecordNumber=[serverResponseNumbers objectAtIndex:an_int_variable];
...
[alertviewmod textFieldAtIndex:0].text= nsRecordNumber;
I get this exception:
-[__NSCFNumber _isNaturallyRTL]: unrecognized selector sent to instance 0xde4dbf0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber _isNaturallyRTL]: unrecognized selector sent to instance 0xde4dbf0'
Just to 'prove' it (assuming NSLog proves it), the following works:
NSLog(@"nsRecordNumber=%@",nsRecordNumber);
or the following line works fine it its place:
[alertviewmod textFieldAtIndex:0].text= @"static text";
What I find fixes it, but is rather inelegant, is to recreate the NSString
. In my case this string is just of an integer number, so I can use this hack:
int number=[nsRecordNumber integerValue];
NSString *nsNumberRecreated=[NSString stringWithFormat:@"%d",number];
[alertviewmod textFieldAtIndex:0].text= nsNumberRecreated;
But this really shouldn't be needed. And I read that '_isNaturallyRTL' is an undocumented function. Can anyone explain this? Perhaps something wrong I'm doing, or a bug? I am using XCode
4.6, targeting iOS
4.3, and testing on an iPad
with iOS
5.1.1.