这是我的 UIAlertView 委托方法。我不知道为什么 myWordsDictionary 在运行应用程序时为空。(注意:_dailyWords 是一个 NSDictionary 对象,书签是一个 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
}
}
提前致谢。