我有下面的代碼問題的NSArray
@interface TestYourInfoViewController : UIViewController {
IBOutlet UIImageView * questionImage;
NSArray *historyQuestions;
int questionHistoryNo;
}
@property(nonatomic,retain) UIImageView * questionImage;
@property(nonatomic,retain) NSArray *historyQuestions;
@property int questionHistoryNo;
-(IBAction)solution:(id)sender;
@end
- (void)viewDidLoad
{
NSArray* array = [[NSArray alloc]init];
historyQuestions = array;
historyQuestions=UmRandomOrder(49, 1, 0);
questionImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"h%@.jpg",[self.historyQuestions objectAtIndex:0]]];
[array release];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(IBAction)solution:(id)sender{
questionHistoryNo= questionHistoryNo+1;
questionImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"h%@.jpg",[self.historyQuestions objectAtIndex:questionHistoryNo]]];
}
當我按下操作按鈕,這讓我異常的行[self.historyQuestions objectAtIndex:questionHistoryNo]
我認爲這個問題是在nsarray莫名其妙,但我不知道它是什麼..例外是 任何人都可以幫助我..
問題歷史不是來自哪裏?爲什麼在使用前添加1?也許你不應該(因爲數組是0索引的)。 – jtbandes
錯誤消息可能實際上非常有用。 – Eiko
檢查陣列中有多少物體?你可能出界了嗎? – dasdom