0

program has crashed at run time.when my code reach to NSMutableArray where I used arryWithObjects method to save some objects in it here is my code

(NSMutableArray *) NumSysToNumSysMultiplyMetd:(NSString *)DecCode lenthOfDecCode
                                   :(int)length NumSysMultiplyValue
                                   :(int)value
{

NSString * step1 = DecCode;
int Step2 = 0;
NSString *step2s=@"=> ";
int finalAnswer=0;

for (int i=length,j=0; i >=0; i--,j++)
{
    NSString *digit;


    digit = [NSString stringWithFormat:@"%c",[DecCode characterAtIndex:j]];

    step1 = [step1 stringByAppendingString: [NSString stringWithFormat:@"%@ * %i^%i +  ",digit,value,i]];

    Step2= [digit integerValue] * pow(value, i);

    step2s= [step2s stringByAppendingString:[NSString stringWithFormat:@" %i +",Step2]];

    finalAnswer =finalAnswer +  Step2;

}
NSMutableArray *mut = [NSMutableArray arrayWithObjects:step1,step2s,finalAnswer,nil];
return mut  
4

1 回答 1

5

问题是您正在尝试将finalAnswer(an int) 添加到NSMutableArray.

int不是一个Objective -C 对象。

尝试转换finalAnswer为 anNSString或 anNSNumber然后存储。

于 2013-07-29T16:17:03.127 回答