Xcode - Access one view controller from multiple view controllers - xcode

I have created an app which in total has 4 view controllers. 2 of these are pages that contain content with an (i) button in the top corner which links to an "about" section of the app. Currently I have 2 separate view controllers displaying the same thing (the about page) as I can't get the two view controllers to link to a single one when I click the button on each respectively.
Is there a way for two view controllers to access one view controller without me having to create a different about page for each one?
Thanks heaps

First you should set the button's target:
exampleButton addTarget:self action:#selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside;
Then, in the button's method:
-(void)buttonAction:(id)sender
{
AboutViewController *aboutViewController = [[AboutViewController alloc] init];
[self.navigationController pushViewController:aboutViewController animated:YES];
}
Don't forget to add the about view controller's header file
#import "AboutViewController.h"
If you use storyboard, you should change the button's action method with
-(void)buttonAction:(id)sender
{
[self.navigationController performSegueWithIdentifier:#"aboutSegueIdentifier" sender:sender];
}

Related

iOS8 UISplitViewController: How to switch to master view in compact width window?

My root view controller is an UISplitViewController, which has a UITableViewController as master view controller. On iPhone (compact width), it looks like a UINavigationController.
Tap a cell to show detail view controller
Tapping the trash button would delete the current note. My problem is how to go back to the master view after that? Since it's an UISplitViewController, it can't pop the current view controller as UINavigationController does.
I had a similar problem and finally found a solution. As I understand it, when in compact width, the detail navigation controller becomes a view controller of the master navigation controller. So all you have to do is:
Determine if only one view is present by checking the split view controller's collapsed property. If it isn't collapsed (e.g. on iPad), you're already showing the table view in addition to the detail view.
If it is collapsed (e.g. on iPhone) get a reference to the master navigation controller via the detail navigation controller and have it pop to its root view controller which, in this case the your table view controller.
This is the code I use in my detail view controller. In your case I think you just need to add this code to the button action in your detail view controller:
if splitViewController!.collapsed {
let detailNavController = parentViewController as UINavigationController!
let masterNavController = detailNavController.parentViewController as UINavigationController!
masterNavController.popToRootViewControllerAnimated(true)
}
Good luck!

iPad Popup Form

I have iPad application with main view controller with a navigation bar at the top. I want to create a signIn button on navigation bar, which should open a popupview with username, password, one additional field and a login button. Clicking login button will close the popover and pass the information from text field back to main view controller.
I have been trying to find something like this on web , but no luck.
Does anyone knows a way to do this ?
You should take a look at UIPopoverController
This is how you initialize and show it:
UIPopoverController *myPopover = [[UIPopoverController alloc] initWithContentViewController:myForm];
[myPopover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionsAny animated:YES];
To get data back from myForm you probably want to use delegation.
myForm.delegate = self; //before presenting de popover

Switching between view controllers without using navigation controller stack

i am creating my first app.i have multiple view controller stack in my app. i want to switch view controllers, so i am using this method:
wallViewController *dvc = [[wallViewController alloc] initWithNibName:#"wallViewController" bundle:nil];
dvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:dvc animated:YES];
[dvc release];
its working fine. but its reloading view controller,like its calling viewdidload each time,but i want to show the previous state of parent view controller as in navigation controller.Please help me.

Dismiss Parent View Controller iOS 5

Im going to a new view using the following code:
UIStoryboard *storyboard = self.storyboard;
finishViewController *finished = [storyboard instantiateViewControllerWithIdentifier:#"finishViewController"];
[self presentViewController:finished animated:NO completion:nil];
Once the new view is loaded the previous view controller is still functioning behind it. Is there a way I can erase it from memory?
Ive tried:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
and
[self.parentViewController dismissModalViewControllerAnimated:YES];
I thought this would be pretty straight forward. T
Thanks
You're presenting a modal view from the parent view controller.
It sounds like what you really want to do is push or segue the finished view controller from the parent view controller.
If you are determined to dismiss / erase the parent view controller, why not first pop the parent view controller and then push/present the finished view controller.
Try using [finished makeKeyAndVisible] it'll make your new controller the only controller.
This can't be done. If you dismiss the parent you'll dismiss both of them.

Tableview reloadData is not being executed -- sometimes

I have a view controller that is called from 2 different places.
1) I call it from a root controller. It is shown and populated. The add button works perfectly. I open a modal form, get the information and return it to the view controller via it's delegate.
- (void)itemsAddViewController:(AddItemView *)itemsAddViewController didAddItem
(OrdersDetails *)orderDetail;
{
if (orderDetail) {
[orderDetailItems addObject:orderDetail];
}
[self fetchOrderDetails];
[lineItemsTableView reloadData];
[self dismissModalViewControllerAnimated:YES];
}
However, when I call it from another view (on the right side of the split view), this same code does NOT reload the table. It adds the data -- if I leave the form and come back, the data is there, but the tableview is not being refreshed. When I step through the code, it gets the the line, but then goes over it like it doesn't see it.
When a modal view controller is presented over the view controller containing -itemsAddViewController:didAddItem: the underlying controller's view is not visible and will therefore be unloaded if the controller receives a memory warning.
As a result your view may not be loaded and your lineItemsTableView outlet may be nil when you call -itemsAddViewController:didAddItem:. Your call to reloadData would need to move to -viewWillAppear: to avoid assuming that your controller's view can have a persistent state when it is not visible.

Resources