2012-01-16 74 views
0

我剛剛實施了inAppSettings套件。我的目標是加載我的默認視圖,然後在右側添加一個導航欄按鈕項目,稱爲「設置」。一旦用戶按下設置按鈕,它會把它們帶到我的設置包,他們可以選擇他們想要的網站,然後再按一次,這會再次加載我的默認視圖,再次用新的url加載webview。從首選項中讀取值

我已經實現了上面剛剛描述的所有內容,但是一旦在設置中進行了選擇並且用戶按下後(又退回設置視圖以返回到默認視圖),則應用程序崩潰並且我不知道爲什麼。我的代碼在下面,如果有人知道爲什麼會發生這種情況,那將是非常感謝。請注意,一旦我在應用程序崩潰後再次運行應用程序,網站會根據它們在崩潰之前選擇的設置正確加載。

P.S.用戶可以點擊選擇的選項有:Google,stackoverflow。

錯誤消息:終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [即將settingsViewControllerDidEnd:]:無法識別的選擇發送到實例0x281c70'

預先感謝您

- (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]; 
} 
+1

TL; DR您可以修剪不相關的代碼以使問題的答案更容易一些嗎? – Costique 2012-01-16 05:02:36

回答

1

待辦事項你實現了InAppSettingKit委託?將此添加到您當前的課程上面

- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController *)sender 
{ 
    // dismiss the view here 
    [self dismissModalViewControllerAnimated:YES]; 
    // do whatever you need to do 
} 
+0

好電話!工作。非常感謝 – Teddy13 2012-01-16 06:00:57