UIAlertView のデリゲート メソッドを次に示します。アプリの実行時に myWordsDictionary が null である理由がわかりません。(注: _dailyWords は NSDictionary オブジェクトで、bookmarked は NSString オブジェクトです。)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex]) {
NSLog(@"Clicked button index !=0");
// Add the action here
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *myWordsPath = [documentPath stringByAppendingPathComponent:@"MyWords.plist"];
NSMutableDictionary *myWordsDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:myWordsPath];
[myWordsDictionary setValue:[_dailyWords objectForKey:bookmarked] forKey:bookmarked];
[myWordsDictionary writeToFile:myWordsPath atomically:YES];
NSLog(@"%@", [myWordsDictionary description]);
[myWordsDictionary release];
} else {
NSLog(@"Clicked button index = 0");
// Add another action here
}
}
前もって感謝します。