Second Segue when pushed not showing navigation bar - iphone

Have two segue in my storyboard. One segue shows navigation bar and navigation item when pushed but second segue doesn't shows navigation bar when pushed
This my code for pushing second segue
- (IBAction)ReadAction:(id)sender {
[self performSegueWithIdentifier:#"MySegue" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"MySegue"]) {
// Get destination view
PDFViewController *pdfviewController = [segue destinationViewController];
}
}
In the storyboard navigationbar and navigation bar title is showing for both segue in storyboard and navigationcontroller is set as rootviewcontroller that is why it is showing in first segue but i wonder why it is not showing only for second segue when execute
Edit:
Solved little bit but still have problem
The view controller which i was trying to push
In that view controller had code like this
NSString *path = [[NSBundle mainBundle] pathForResource:#"Paper" ofType:#"pdf"];
PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:path];
//[self presentViewController:page animated:NO completion:NULL];
When i commented out this statement from above code then it shows navigation bar and backbuttonitem that is what i was looking for
[self presentViewController:page animated:NO completion:NULL];
but now after commenting it doesn't displays pageviewcontroller in the pushed view controller.
Now how can i display pageviewcontroller.
Edit:
Just added
[self.view addSubview:page.view];
but now another problem pageviewcontroller is displaying with navigation bar and all that but now not turning pages over using curl effect with previous commented statement it was turning pages over
Help will be really appreciated.
Thanks.

I think the below should work for your needs. One pushes and one presents simply.
PDFViewController *pdfviewController = [segue destinationViewController];
[self.navigationController presentViewController:pdfviewController animated:YES];
or
[self.navigationController pushViewController:pdfviewController animated:YES];
Try both.

Related

Navigate to UITableViewController by selecting UITableView Cell

I'm Using UITableView without a navigation controller. My problem is, when I click a particular cell, It doesn't push to another UIViewController.
Here is my code,
-(void)goToMyView
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
TOMenuViewController *vc = [sb instantiateViewControllerWithIdentifier:#"MyViewController"];
[self.navigationController pushViewController:vc animated:YES];
}
How do I move to another view controller and come back from it.
Instead of this line of code:
[self.navigationController pushViewController:vc animated:YES];
use this line of code:
[self presentViewController:vc animated:YES completion:nil];
When you want to go back to your old view controller in the new view controller use:
[self dismissViewControllerAnimated:YES];
And for animation before you present your view controller use:
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
try to use prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//you have to give an id to segue, in storyboard
if ([[segue identifier] isEqualToString:#"detail"]) {
//passing strings or whatever you want here so:
[segue.destinationViewController setStringDetail: yourString];
}
in detailViewController the back button is automatically created
see my answer here, how to change the modal segue's animation to look like a push segue.
Pushing a view to a UINavigationController that's not in the same view hierarchy

Why won't my UITableView segue to a detail view?

I wanted to have a tab bar controller, then a table view controller with a corresponding detail view. I am new to this, so I tried combining Apple's SimpleDrillDown:
http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html
...with Ray Wenderlich's tutorial on Storyboards:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
Ray's shows you how to set up the tabs and get the first table view, but then doesn't show you how to get a detail view, so then I tried to learn how to get the detail view from Apple's SimpleDrillDown (which doesn't have the tab bar controller).
My program runs with no errors, but when you click on a row in the table view (FactSheetsViewController), it stays blue (selected) and never segues to my FactSheetsDetailViewController. If I put a breakpoint in my table view class at this method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"DisplaySelectedFactSheet"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
FactSheetsDetailViewController *detailViewController = [segue destinationViewController];
detailViewController.factSheet = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}
The breakpoint is never reached when I run the program and click on a cell.
I'm not sure what other code to post, because I'm not sure what I did wrong. I'm wondering if I initialized things incorrectly in my AppDelegate?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0];
FactSheetsViewController *factSheetsViewController = [[navigationController viewControllers] objectAtIndex:0];
DataController *controller = [[DataController alloc] init];
factSheetsViewController.dataController = controller;
self.dataController = controller;
return YES;
}
Or, if I'm not setting things up correctly in the storyboard somehow. I set the identifier to my segue from FactSheetsViewController to my FactSheetsDetailView to "DisplaySelectedFactSheet" in the attributes inspector.
I'm happy to post more details if it would help - please just let me know! Thank you.
In Xcode, you need to create a segue between the table cell (prototype) and the FactSheetsDetailViewController. Then, also in Xcode, edit the segue name to be DisplaySelectedFactSheet.

navigation bar is hidden when i return back to view in iOS

I am new in iPhone development. I created an app which use a navigation bar using storyboard. My problem is that i am opening a viewB programmatically from viewA on button click and it successful. Now to go back to viewA i have used cancel button. when i click on cancel button (previous) the (viewA) is opened but navigation bar is not shown. and viewA have navigation bar control but viewB does not.
Thanks in advance
View A
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
EditViewController *viewController = (EditViewController *)[storyboard instantiateViewControllerWithIdentifier:#"EditViewController"];
[self presentViewController:viewController animated:NO completion:NULL];
View B:
- (IBAction)cancelButtonPressed:(id)sender {
if ( lables != NULL) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ScannerViewController *viewController = (ScannerViewController *)[storyboard instantiateViewControllerWithIdentifier:#"ScannerViewController"];
[self presentViewController:viewController animated:NO completion:NULL];
}
else{
[self.navigationController popViewControllerAnimated:YES];
}
You are presenting the viewB & popping it using self.navigationController, you should use one way, either use presentviewcontroller & dismissviewcontroller.
[self dismissViewControllerAnimated:YES completion:nil];
For your scenario it is best to use UINavigationController
e.g
Pushing:
[self.navigationController pushViewController:viewController animated:YES];
Closing
[self.navigationController popViewControllerAnimated:YES];
You have to use a navigation controller, in your StoryBoard select your view A, Editor Menu > Embed In > Navigation controller.
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html
If you are using storyboard no need to present the viewController programmatically. press and hold ctrl, drag from viewCA to viewCB and select model from popup menu.
For dismissing the viewController
[self dismissViewControllerAnimated:YES completion:nil];
If you want to send any data to viewCB give segue identifier (for example "segid")
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:#"segid"])
{
//write your code here.
}
}
This method will get called automatically (delegate) while presenting (of pushing) viewController.
I was also facing the same problem. The solution is to never select the modal on click on the back button, because modal covers your whole view and that's why on the back screen navigation controller is not showing. So don't make connection for back button, just write the code for back button.
[self dismissViewControllerAnimated:YES completion:nil];
When you needed (e.g. viewDidAppear method) use,
[self.navigationController setNavigationBarHidden:NO animated:YES];

Dismiss ModalView does not work here

So I have a tabBarController as a modalview, and it shows up fine. As I click some of the tabs, the views are loading properly. I want to dismiss the modalView when I click on tabBarController.selectedIndex ==4
So I write in the viewDidLoad and also tried in the viewWillAppear of that view controller to dismissModalViewController and it does not work.
I tried
[self.parentViewController dismissModalViewControllerAnimated:YES];
// ... And also //
[self dismissModalViewControllerAnimated:YES];
Could someone point out why it does not work ?
All you have to do is pass a reference to the modally presented VC pointing on the VC that will present it modally.
Define a weak reference as a property in the UITabBarController subclass, and send a message to dismiss it when required.
For example using a property named mainViewController :
MySubclass *tbController = [[MySubclass ....];
tbController.mainViewController = self;
[self presentModalViewController:tbController animated:YES];
Then in MySubclass define
#property(assign) UIViewController *mainViewController;
and synthesize it, then when the tab you want gets selected :
[self.mainViewController dismissModalViewControllerAnimated:YES];
I think the 4th view controller (of the tab bar controller) is trying to get dismissed by the line
[self.parentViewController dismissModalViewControllerAnimated:YES];
Since this 4th view controller was not presented by any controller, this wont work.
And it is dismissing it's modal view controller by the line
[self dismissModalViewControllerAnimated:YES];
Since, this 4th view controller did not presented any view controller, this again should not work.
You want to dismiss the tab bar controller and not its 4th view controller.
Basically, you can get the reference of tab bar controller from the 4th view controller.
As, [yourFourthViewController.tabBarController.parentViewController dismissModalViewControllerAnimated:YES];
I am guessing this without actually trying. Let me know if this works.
If you have the UINavigationController as the parent controller then the following line will work for you.
[self dismissModalViewControllerAnimated:YES];
But here I think you have the UIViewController is the parent controller instead of the UINavigationController. So, You can do one thing when presentModalViewController.
if(objView == nil)
objView = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:objView];
[self presentModalViewController:navigationController1 animated:YES];
Let me know if you need more help or any questions.

Hide detail View

I need to hide a detail view that is shown when clicked on a tableviewitem
- (IBAction)done:(id)sender {
[self.delegate OrderDetailsViewDidFinish:self];
}
It is all connected up with in the, xib and .h but the view doesnot close, it is loaded via this code and loads great:
//Initialize the detail view controller and display it.
OrderDetailsView *dvController = [[OrderDetailsView alloc] initWithNibName:#"OrderDetailsView" bundle:[NSBundle mainBundle]];
dvController.selectedOrder = (#"%#",selectedOrder);
[self presentModalViewController:dvController animated:YES];
[dvController release];
dvController = nil;
the trouble comes when closing it, please not i ahve all the correct .h in the detail view
Thanks
Mason
If you present a controller as a modalViewController then when hiding it you only need this:
- (IBAction)done:(id)sender {
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
When you use modals a Parent-Child relation is created between two controller (the newly presented is the child) so you can call the previous controller with self.parentViewController from this new controller ;)