NSarray Error, When setting uibutton
开发者_开发技巧i am trying to parse the data i require from the string i input however i keep getting an error. could somebody read this code and tell me were i am going wrong please.
NSArray *AllDataArray = [RawMessage componentsSeparatedByString:@"|"];
NSLog(@"%@", AllDataArray);
// Should we bomb Libya ?,0,0,06/04/2011,30/04/2011|Will England win in the olympics ?,0,0,18/04/2011,18/05/2011|Is White the new Black ?,0,0,21/04/2011,21/05/2011|
//do a for loop and and the questions were ever needed using [AllDataArray objectAtIndex:0];
NSArray *Question1 = [[AllDataArray objectAtIndex:0] componentsSeparatedByString:@","];
NSArray *Question2 = [[AllDataArray objectAtIndex:1] componentsSeparatedByString:@","];
NSArray *Question3 = [[AllDataArray objectAtIndex:2] componentsSeparatedByString:@","];
//Update ui buttons
[btnQuestion1 setTitle:[Question1 objectAtIndex:0] forState:UIControlStateNormal];
[btnQuestion1 setTitle:[Question1 objectAtIndex:0] forState:UIControlStateHighlighted];
[btnQuestion1 setTitle:[Question1 objectAtIndex:0] forState:UIControlStateDisabled];
[btnQuestion1 setTitle:[Question1 objectAtIndex:0] forState:UIControlStateSelected];
Error i get is sigabrt in man.m when i have not touched main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); //ERRORS HERE
[pool release];
return retVal;
}
the error may not be in the code you just posted, as I just took your code and recreated a project and it runs fine without error.
BUT.. one thing that may be causing an issue somewhere else is your AllDataArray. Take a look at the output once you parse serarate the string on the "|", you end up with an empty string in the last item... AND, I assume you split that string later on based on the ",".. AND I might assume that you reference a ordinal position of that array without doing any bounds checking, like you do here
NSArray *Question1 = [[AllDataArray objectAtIndex:0] componentsSeparatedByString:@","];
if that array does not have any elements, you will throw an error that if unhandled should bubble up to main();
BUT.. again, a lot of assumptions there.
精彩评论