我的应用程序中有一个设置视图,用户可以选择其中一个选项卡显示来自播客的 mp3 提要或来自播客的 mov。我在第一次运行应用程序时设置它以显示 AlertView 询问他们喜欢什么。我在 applicationDidFinishLaunching 中这样做:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (! [defaults boolForKey:@"notFirstRun"]) {
UIAlertView *firstrun = [[UIAlertView alloc] initWithTitle:@"Sermon Preference" message:@"Do you prefer audio only, or video sermons? (This setting can be changed at any time in the Settings Page.)" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Audio", @"Video", nil];
[firstrun show];
[firstrun release];
[defaults setBool:YES forKey:@"notFirstRun"];
}
然后我在 AppDelegate 中设置
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *nope = @"Audio";
[defaults setObject:nope forKey:@"videosermons"];
[defaults synchronize];
}
if (buttonIndex == 1) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *yup = @"Video";
[defaults setObject:yup forKey:@"videosermons"];
[defaults synchronize]; }
}
在用于布道的导航控制器的根视图(这是布道的音频列表)上,我在 viewWillAppear 中设置了这个:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *currently = [defaults objectForKey:@"videosermons"];
if ([currently isEqualToString:@"Video"]) {
self.videoView = [[[VideoPodcastTableView alloc] initWithNibName:@"VideoPodcastTableView" bundle:[NSBundle mainBundle]] autorelease];
[self.navigationController pushViewController:_videoView animated:NO]; }
if ([currently isEqualToString:@"Audio"]) {
}
我还设置了一个带有segmentControl 的设置选项卡以反映已选择的内容。这是问题:
如果我在 firstRun 弹出窗口中单击视频,然后直接进入讲道选项卡,它会停留在音频讲道上。然后我可以导航到“设置”选项卡,它将显示已选择的视频。现在,无需选择任何内容,我可以再次进入讲道选项卡,它现在将进入视频讲道。为什么直到我进入设置后才收到更改消息?