首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从首选项中读取值

从首选项中读取值
EN

Stack Overflow用户
提问于 2012-01-16 12:35:23
回答 1查看 232关注 0票数 0

我最近刚刚实现了inAppSettings工具包。我的目标是加载我的默认视图,然后在右侧添加一个名为"settings“的导航栏按钮项。一旦用户按下设置按钮,它将把他们带到我的设置捆绑包,在那里他们可以选择他们想要的网站,然后按back,这将再次加载我的默认视图,webview再次加载新的url。

我已经实现了我刚才描述的所有东西,但是一旦在设置中进行了选择,用户按下了back (也就是关闭设置视图返回到默认视图),应用程序就会崩溃,我不知道为什么。我的代码如下,如果有人知道为什么会发生这种情况,我将不胜感激。需要注意的是,一旦我在应用程序崩溃后再次运行它,网站就会根据他们在崩溃前选择的设置正确加载。

附注:用户可以点击选择的选项有: Google,stackoverflow。

错误消息:由于未捕获异常'NSInvalidArgumentException',正在终止应用程序,原因:‘-即将到来的settingsViewControllerDidEnd::无法识别的选择器已发送到实例0x281c70’

提前谢谢你

代码语言:javascript
复制
- (IASKAppSettingsViewController*)appSettingsViewController {
    if (!appSettingsViewController) {
        appSettingsViewController = [[IASKAppSettingsViewController alloc] initWithNibName:@"IASKAppSettingsView" bundle:nil];
        appSettingsViewController.delegate = self;
    }

    return appSettingsViewController;
}

-(IBAction)selectSettings {
    UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:self.appSettingsViewController];
    //[viewController setShowCreditsFooter:NO];   // Uncomment to not display InAppSettingsKit credits for creators.
    // But we encourage you not to uncomment. Thank you!
    self.appSettingsViewController.showDoneButton = YES;
    [self presentModalViewController:aNavController animated:YES];
    [aNavController release];
}

-(NSDictionary *)intialDefaults {
    NSArray *keys = [[[NSArray alloc] initWithObjects:kPicture, nil] autorelease];  
    NSArray *values= [[[NSArray alloc] initWithObjects: @"none", nil] autorelease];
    return [[[NSDictionary alloc] initWithObjects: values forKeys: keys] autorelease];
} 

-(void)setValuesFromPreferences {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults registerDefaults:[self intialDefaults]];
    NSString *picturePreference= [userDefaults stringForKey:kPicture];

    if([picturePreference isEqualToString:@"google"]) {             
        [self getUpcoming:@"http://www.google.ca"];
    } else 
    if ([picturePreference isEqualToString:@"stackoverflow"]) {
        [self getUpcoming:@"http://www.stackoverflow.com"];
    } else {
        [self getUpcoming:@"http://www.yahoo.com"];
    }
}

-(void)getUpcoming:(id) hello {
    NSURL *url= [NSURL URLWithString:hello];
    NSURLRequest *requestURL= [NSURLRequest requestWithURL:url];
    [web loadRequest:requestURL];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    web.hidden=NO;
    [spinner stopAnimating];
    [load_message dismissWithClickedButtonIndex:0 animated:TRUE];
    pic1.hidden=YES;
}

-(void) loadMethod {
    load_message = [[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];

    spinner= [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    spinner.center = CGPointMake(135.0, 60.0);

    [load_message addSubview:spinner];
    [load_message show];
    [spinner startAnimating];
    [self performSelector:@selector(setValuesFromPreferences) withObject:nil afterDelay:0.0];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UIBarButtonItem *settingButton= [[UIBarButtonItem alloc]
                               initWithTitle:@"Settings"
                               style:UIBarButtonItemStyleBordered
                               target:self
                               action:@selector(selectSettings)];

    self.navigationItem.rightBarButtonItem = settingButton;
    web.hidden=YES;
    pic1.hidden=NO;
}

- (void) viewDidAppear:(BOOL)animated {
    [self loadMethod];
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-16 13:30:10

你实现InAppSettingKit委托了吗?将它添加到上面的当前类中

代码语言:javascript
复制
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController *)sender
{
    // dismiss the view here
    [self dismissModalViewControllerAnimated:YES];
    // do whatever you need to do
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8875805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档