0

だから私は、ボタンをクリックした後にメモを NSUSerDefaults に保存するメモアプリを構築しています。そのビューを読み込んでメモを追加し、ボタンをクリックして初めて保存すると、正しく機能します。ただし、ビューを離れずに新しいメッセージを追加し、ボタンをクリックして保存しようとすると、アプリがクラッシュします。その理由が本当にわかりません。現在使用している xcode バージョンでは、エラーの詳細はあまりわかりませんが、これはわかります

0x00015a9b  <+1175>  xor    %eax,%eax
Program received signal 'SIGABRT'

これは、ボタンのクリック後にトリガーされる IBAction のコードです (送信イベント)。

-(IBAction)saveNote{
NSUserDefaults *prefs=[NSUserDefaults standardUserDefaults];
//If empty add text to synthesized array and then add the array to the USer defaults
if([[prefs stringArrayForKey:@"Subjects"] count]==0){
    NSLog(@"Went through here");
    [notesSubject addObject:writeNote.text];
    [prefs setObject:notesSubject forKey:@"Subjects"];

    NSLog(@"The length of the array is %d",[notesSubject count]);

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Note Saved" message:@"Your note was saved" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    //[notesView.tableView reloadData];

}
//If not empty, get the array stored in the user defaults and set it to a temp array, add text to that temp array and then place the temp array back to the user defaults.
else{
    newSubjects=[[NSMutableArray alloc]init];
    beforeSubjects=[[NSArray alloc]init];

    newSubjects= [prefs stringArrayForKey:@"Subjects"];
    [newSubjects addObject:writeNote.text];
    [prefs setObject:newSubjects forKey:@"Subjects"];
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Note Saved" message:@"Your note was saved" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    //[notesView.tableView reloadData];
}


}

ええ、2回目のクリックでアプリがクラッシュする理由がよくわかりません。

4

1 に答える 1