我正在尝试从我输入的字符串解析我需要的数据但是我一直收到错误。有人可以阅读这段代码并告诉我,我是不是会出错。
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];
当我没有触及main.m
时,我得到的错误是man.m中的sigabrt#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;
}
答案 0 :(得分:0)
错误可能不在您刚刚发布的代码中,因为我刚刚接受了您的代码并重新创建了一个项目,并且运行正常而没有错误。
但是......可能在其他地方引起问题的一件事是你的AllDataArray。一旦解析了“|”上的字符串,看一下输出,最后一个项目中的空字符串就结束了......并且,我假设您稍后根据“,”分割该字符串。我可能会假设您引用该数组的序号位置而不进行任何边界检查,就像您在此处一样
NSArray *Question1 = [[AllDataArray objectAtIndex:0] componentsSeparatedByString:@","];
如果该数组没有任何元素,则会抛出一个错误,如果未处理应该冒泡到main();
但是......那里有很多假设。