我想從我的NSMutableArray獲取數據,如果我嘗試這個NSLog(@"%@",[A_array objectAtIndex:5]); // works fine
如何從整數值中獲取來自NSMutableArray ObjectAtIndex的數據?
NSLog(@"%@",[A_array objectAtIndex:var_Count_Answer_A]); // var_Count_Answer_A =5; and crash
任何想法或建議,將不勝感激我這樣做
-(void)ViewDidLoad{
A_array = [[NSMutableArray alloc] init];
A_array = [NSMutableArray arrayWithObjects:@"4",@"6",@"2",@"3",@"0",@"5",@"1",@"2",@"4",@"1",@"0",@"2",@"4",@"2",@"0",@"3",nil]
var_Count_Answer_A = 0; // int
}
-(void)method_Second {
NSLog(@"%@",[A_array objectAtIndex:var_Count_Answer_A]); // This line is crashing if I click button again. First time line works fine but if we click button again and var_Count_Answer = 2 then it will crash.
NSString *str1 = [[NSString alloc]initWithFormat:@"%@",[A_array objectAtIndex:var_Count_Answer_A]]; // If I comment on NSLOG then this line will crash
A = [str1 integerValue];
NSLog(@"A is %d",A);
var_Count_Answer_A ++;
}
。
發表您的崩潰日誌。 – Balu
其中是定義var_Count_Answer_A –
您是否使用ARC?這些iVars在哪裏定義? – Stavash