Being new to iPhone development I am really struggling with this concept. I have built an App which is not quite running the way that it should. I have a TabBar app. The secondViewController is essentially a form which I use to collect information about daily exercise. I have embedded this secondViewController into a Navigation controller so that I can push to a datePicker view and return with the date. I also push to a pickerView for exercise type and return with data. At least this is the intended process. I use the prepareForSegue to push the picker views and return to the secondViewController carrying data between them with each segue.
What I find is happening is that instead of pushing to the picker views and returning to the secondViewController my app seems to progress in a linear fashion. To be more precise it seems to push to the date picker, then push to a new 'instance' of the secondViewController, then push to pickerView, and then to another new instance of secondViewController. This means that when my users eventually touch the save button, they have to use the back button in the navBar to get back to the original secondViewController.
[Have an image to add but can't post it as I have reputation under 10 :-( ]
I have read Apple's documentation on managing the stack and hierarchy, but I just seem to have confused myself more than anything else. I have also searched for answers and tutorials, but I am either missing something or there is no clear explanation of how this is supposed to work that I can find. Can anyone tell me how to push to a pickerView and then return, or at least to return programmatically to the original secondViewController when the save button is finally touched?
To go Back in hierarchy in UINavigation Controller you can use
[self.navigationController popViewControllerAnimated:YES];
Related
I have an initial ViewController that is a TableView with lots of data. I have a title bar button item that links to another TableView with a summary of the data in the first ViewController. I currently have it so that when you click on a cell, it redirects the user back to the first ViewController and scrolls them to the proper cells. However, it adds the view to the stack and doesn't actually move them back properly. I think I would be able to do this through Unwind segues, but I can't seem to get them to work through cell clicks. Is there a better way that I can achieve this?
When I switch to the other view, I also need to set two variables in the initial controller to tell it what index to scroll to.
1.UNWind Segue :
suppose that we need to programmatically trigger the backward navigation, based on an interaction with something other than the default “back” button on the navigation bar. How would you do it? Yep – you’ve got it: by using an unwind segue.
2.Other way is usual : PopViewController Method
As per your question , you can go with option 2 which is more easy .
As far as Sending data from SecondViewController to FirstViewController you can use delegate pattern to send data back.
Here is few useful post : https://stackoverflow.com/a/25523091/3400991
Feel free to comment. Thanks
I'm having a hard time understanding what approach I should take. I have a TableView controller with a list of questions, if you click a row it pushes a new QuestionViewVontroller that displays the question, answers, and next button (or done button). When a user clicks next I want to load the next question (from the tableview list) but I still want the navigation to work (back button will take you to TableView).
I'm starting to think I should keep the same QuestionViewController and just load in the question data. Is this right? Or should I use a modal view?
You have a couple of options here.
Use the same QuestionViewController and just repopulate it, like you mentioned.
Push a new QuestionViewController and use custom back button that either pops to the root view controller or pops to a given view controller.
The code for both options in #2 is below, where "self" is the current view controller (your question controller).
[self.navigationController popToRootViewControllerAnimated:YES]; //this would pop to your UITableViewController, assuming it was the root
[self.navigationController popToViewController:yourTableViewControllerHere Animated:YES]; //this would work as long as you passed a reference to your UITableViewController to your question controllers
It's up to you how you choose to solve your issue. However, if you decide to use the same QuestionViewController, include a catchy animation when importing the new question so the user knows what is happening and to make your app that much cooler :)
I am designing an iPhone application with a home page. This page has multiple buttons (6) that go to different things.
2 buttons are a simple view that just have some information and go back to the home screen. The next button opens up an email and I believe that will just be one view, so not a whole lot different than the other two.
Here is where it gets complicated. One button will take a picture, and another will select one from the library. Once that is done it will edit it and create an object that I will create. That object will be stored in an array, which will be opened by the last button one the home page and a UITableViewController will control that.
My first question is should I use a navigation based view controller or just a view controller that I can create myself? Or should I use something that I don't even know about?
Please Help!!! And if you help a sincere thank you!
EDIT:
Well i tried it my own way first and the only issue i'm having is this code
- (void) displayView:(int)intNewView {
NSLog(#"%i", intNewView);
[home.view removeFromSuperview];
Instructions *i = [[Instructions alloc]init];
instructions = i;
[self.view insertSubview:instructions.view atIndex:0];
}
It is in my SwitchClass, which controls the Main Window's view. I know it is working there because when it first runs the switch class directs it to the home screen. I know the method is being called because the console is displaying the NSLog thing, but it just won't switch.
Aside from the fact that you have 6 buttons, I would try and use a UITabBarController for what you are trying to do; it would seem more natural to me (but you should find a way to reduce you 6 button to 5, otherwise they will not be displayed all at once).
Otherwise, a UINavigationController seems fine to me. For each button you push a new controller to deal with that button functionality, then you pop back. It should work easily.
EDIT:
have you tried with?
[self.view addSubview:instructions.view];
Your first question Yes you should use navigation based controller ... so when you press any button will open the other view controller with animation.. also Navigation Based Controller keep track of the parent controller if you have any created objects will be retained in the parent view controller that is the root of the Navigation.
here is the steps that you should use.
1-Create Navigation controller in the main application delegate and make it's root is the view controller.
2-when you push the view controller that have 6 buttons .
3- you can check this link for get photo album also if you have changed the source type to camera then you can get the image...
Photo Libaray
4- once you get the image you can add it to NSMutableArray that exist on the NavigationViewController root in your case will be the view which have the 6 buttons.
5-sice every time you want to view the array which contain the photos you will initialize the data source of the uitableviewcontroller with the array that you save photos on.
Thanks
I think the problem is coming from one of two places:
As I understand it, these are all different View Controllers, correct? And they have their own xib files? If that is true, then calling:
Instructions *i = [[Instructions alloc]init];
is insufficient. You need to use
Instructions *i = [[Instructions alloc] initWithNibNamed:#"Instructions"];
in order to include that view that you have already constructed in the interface builder.
The other thing I see potentially going wrong is that you are inserting all the views at the same index. Think of the index as a layer in photoshop. If you want the new view to be visible overtop of the last one, then it needs to be a higher index. This is handled automatically if you use addSubview: instead of insertSubview: atIndex:
Something is puzzling me, after going through my app with instruments, it is a UINavigationBased App, it noticed this.
Each time a tableView cell is tapped and I do this:
GenericTableViewController *someViewController = [[Generic TableViewController alloc] init];
[self.navigationController pushViewController:someViewController animated:YES];
[someViewController release];
I then tap the back button and look in Instruments to see how many living instances of the GenericTableViewController there exists. There is 1 before the back tap, and 0 afterwards.
This is great, good clean memory management by the UINavigationController.
However, other places in the app I don't use the back button to leave a view, in some viewControllers tapping one of my custom buttons will run code completely like the above, but the viewController, in which I tapped the custom button, will not be released.
I guess I understand why, the navigationController makes a judgment call, that I might be pushing something on to the stack and that I will return later, so it keeps the controller in its memory. This must mean that tapping the back button uses a [self.navigationController popViewController]. Ok.
The problem is now that each time I visit a view that isn't left using a "back" button in the navigationBar, it
will not be released. The count allocation in Instruments just goes up each time I visit a view, until I have like 20 objects living.
I tried putting a [self.navigationController popViewController] in the selector for my custom buttons. Meaning that I manually pop the visible viewController before pushing a new on to the stack.
But the allocation count does not go down? guess the "back" button does not use this technic after all...
I also tried using popToViewController, since I always know if the controller has been on the stack or not. But to use the popToViewController, I need to keep a reference around for the view.
Is there some sound way of saying to the UINavigationController: If this viewController is on your stack, please display it, if not please instantiate it, push to the stack and display it.
The challenge here is probably that not all my navigation in the NavigationController is completely linear. I will sometimes have to go from stack item no. 2 to stack item no. 5, back to 3 etc.
So is there a way to do this, while still having the UINavigationController making sure to release my viewControllers and not instantiating the same viewController several times?
You could try to access UINavigationController's viewControllers property to get a NSArray of all the view controllers currently on the navigation stack. Then use containsObject: to check if the view controller is already on the stack.
If it is, then use popToViewController:animated: to show the view controller. If it is not on the stack then just use pushViewController:animated:.
If this does not help you, maybe setViewControllers:animated: is the right method.
In my application i have used the UiViewController and able to push the other view using the PushViewController.
But, whenever i am using the presentModalViewController at that time i am not able to get whole functionality of the BackButton click event on the view which is working fine for the pushviewController.By using the debug i am able to reach at the function,but not able to execute the whole piece of code into that function.i have used below code.
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
But not able to get back to the push page.None of the lines effect is seen on the application.
Can any body give me any suggestion if i have done something unusual from transferring from PushviewController to presentModalViewController?
i just want the presentModalViewController in my application for some effect as horizontal or vertical.But,i am not able to see any effect of the event on that view.i am able to see the horizontal and vertical effect.
please guide me with proper resolution or any other solution which would be appreciated.
Thanks,
Mishal Shah.
I don't think the navigationController property is set inside of your ModalViewController. So saying self.navigationController wouldn't work inside of your Modal View Controller. That is, if that's even where you put it, I don't really understand from the way you formatted your question.
If you want more help post some more code/format it better/start accepting more answers to your questions.
I think accepted practice is to dismiss the modal view controller from the view control in which you presented it. Use a notification to send a message back to the presenting controller and dismiss it there.
I think that is what you were asking, the question is somewhat unclear.