我在iphone应用程序中添加了一个导航控制器,从我的主屏幕到桌面视图所需的详细信息。我能够在视图之间来回导航。我想要的是直接导航详情查看我的主屏幕。有没有可能做到这一点?
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.hidesBackButton = TRUE;
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)]; self.navigationItem.leftBarButtonItem = saveButton;
id1 = [[NSUserDefaults standardUserDefaults] valueForKey:@"id1"];
theTitle = [[NSUserDefaults standardUserDefaults] valueForKey:@"theTitle"];
self.title=theTitle;
NSLog(@"hi %@", id1);
hello=@"hello";
NSLog(@"ahhhha sdfgs :%@",theTitle);
urlAddress = [NSString stringWithFormat:@"http://dev-parkguiden.knutpunkten.se/Api/GetPark?parkid=%@",self.id1];
baseURL =[[NSURL URLWithString:urlAddress]retain];
jsonData=[NSData dataWithContentsOfURL:baseURL];
NSDictionary *items=[NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
boom=[items objectForKey:@"description"];
latitude=[items objectForKey:@"latitude"];
longitude=[items objectForKey:@"longitude"];
NSLog(@"retard:%@",latitude);
NSLog(@"retard:%@",longitude);
NSString *html = [NSString stringWithFormat:@"<html><body><p>%@</p></body></html>", boom];
[self.webview loadHTMLString:html baseURL:nil];
[[NSUserDefaults standardUserDefaults] setValue:latitude forKey:@"lat"];
[[NSUserDefaults standardUserDefaults] setValue: longitude forKey:@"lot"];
[[NSUserDefaults standardUserDefaults] setValue: theTitle forKey:@"title"];
}
答案 0 :(得分:3)
[self.navigationController popToRootViewControllerAnimated:YES];
这将弹回导航控制器的rootviewController
答案 1 :(得分:1)
您只需设置自定义后退按钮并设置按钮点击事件
//首先隐藏按钮
self.navigationItem.hidesBackButton = TRUE;
/// Add new Back Button
UIButton *back = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
back.frame = CGRectMake(0, 0, 50, 32);
[back setShowsTouchWhenHighlighted:TRUE];
[back setBackgroundImage:[UIImage imageNamed:@"backBtn.png"] forState:UIControlStateNormal];
[back addTarget:self action:@selector(backBtnTap:) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithCustomView:back];
self.navigationItem.leftBarButtonItem = backBtn;
/// Press button event to go to root or say home page
-(void)backBtnTap:(id)sender{
[self.navigationController popToRootViewControllerAnimated:YES];
}