我刚刚实施了inAppSettings工具包。我的目标是加载我的默认视图,然后在右侧添加一个名为“设置”的导航栏按钮项。一旦用户按下设置按钮,它就会将它们带到我的设置包中,在那里他们可以选择他们想要的网站,然后按回来再次加载我的默认视图,再次使用新网址加载webview。
我已经实现了上面描述的所有内容,但是一旦在设置中进行选择并且用户按下(也就是取消设置视图以返回默认视图),应用程序崩溃并且我不知道为什么。我的代码如下,如果有人知道为什么会这样,那将非常感激。需要注意的是,一旦我崩溃后再次运行应用程序,网站会根据他们在崩溃前选择的设置正确加载。
P.S。用户可以单击选择的选项有:Google,stackoverflow。
错误消息:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [Upcoming 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];
}
答案 0 :(得分:1)
您是否实现了InAppSettingKit委托?将其添加到上面的当前班级
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController *)sender
{
// dismiss the view here
[self dismissModalViewControllerAnimated:YES];
// do whatever you need to do
}