2011-04-28 78 views
0

我想解析我输入字符串所需的数据,但是我不断收到错误。有人可能会读这段代码,并告诉我我错了。NSarray错误,当设置uibutton

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]; 

错误我得到的是在man.m SIGABRT的时候我都没有碰过的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; 
} 
+1

什么是错误信息?并通过'(@“%@”,AllDataArray)丢失了NSLog;' – Joe 2011-04-28 13:19:45

+0

你能发布堆栈跟踪吗?它可能表明什么导致了sigabrt。 – dredful 2011-04-28 13:39:52

回答

0

错误可能不是你刚才发布的代码,因为我只是把你的代码,重新创建了一个项目,它运行良好,没有错误。

但是..有一件事情可能在其他地方引起问题是你的AllDataArray。在解析字符串“|”后,查看输出结果,最后一个项目中会出现一个空字符串...并且,我假设您稍后根据“,”分割该字符串..和我可能会认为您引用数组的顺序位置没有做任何边界检查,就像你在这里做

NSArray *Question1 = [[AllDataArray objectAtIndex:0] componentsSeparatedByString:@","]; 

如果数组没有任何元素,就抛出一个错误,如果未处理应该冒泡到main();

但是..再次,那里有很多假设。