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 :)
Related
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:
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];
I have a navigation controller which I push a new tableviewcontroller for each received question to be asked to the user, so in stack it builds up to 30 controllers if there has been 30 question is asked.
The difficulty is that in some of the tableviewcontrollers I want to get the input from user by using another navigation controller inside that tableview: for example in the tableview(which is one the many views in the stack) there may be uitablecell with an arrow on the right saying choose the books you want to order, and when he clicks arrow a new tableview will slide in which includes the books to be choosen multiply with a checkmark, and then he will choose and back to main tableview and continue the main navigation there.
How can implement a new navcontroller inside the main navigation controller? or any better ideas?
EDIT: That can be an idea to push the detail view to the same controller, but then they will get popped immdidatly when user "backs" but I want to show the books (which are chosen in detail view) the main table, and when user clicks again to that cell, detailview will come with previous selected books. is this a good approach
Putting an UINavigationController inside a UINavigationController is a bad idea. What you seem to really want is persistence of state data after popping some of the view controllers off your navigation controller's stack.
I would put that state information into a persistent object. If it's a tiny amount of state data I may add that data to an existing object that I know is persistent, such as the app delegate or the root view controller. I would save a more complicated set of persistent data to a custom object. This object would be retained by the root view controller, and a reference would be given to each successive view controller. This object would have the data that may have been collected by a controller that was popped off the navigation stack and therefore no longer exists.
I don't really get why you dont just push the detailview of the uitableviewcontrollers to the main UINavigationController..
Could you explain that a little bit more detailed?
I have no rights to comment your question, so I am afraid I have to post this as an answer.
MfG,
SideSwipe
Sorry I can't show code for this question - it should be fairly simple to explain..
I have an array of data (object1, object2, object3, etc)… I have one tableview that lists these objects (object1.title, object2.title, etc) and upon clicking it push's a viewcontroller that shows the detail of each object. Now, rather than have to press Back on each detail view, I'd like to put a next button on the detail page..
I could easily push a new controller, however it would end with a chain of:
List View -> Detailview1 -> Detailview2, etc..
which would be a pain to traverse back up the stack.. Can the parent view controller be removed / changed easily or is this not the best way to do it?
Cheers.
You can always pop back to a specific index in the stack. So you could have a back button that pops back to the parent. If there is no real reason that the user would need to go back through the detail view controllers you could swap controllers by replacing the stack with a new stack using setViewControllers:animated: Look through the UINavigationController documentation and see whats possible.
This code will "pop" the view contoller off the view, so it removes it, instead of overlaying another view on top of it. Add this to your button action
[self.navigationController popViewControllerAnimated:YES];
could anyone help me with the next question. I am working on an app with the navigation similar to Notes app has. The problem I faced i how to implement navigation within one level and keep root view as the previous screen. So the scenario I need to achieve:
1. Drill down from the top level list to the detailed view.
2. From this detailed view navigate to the detailed view of the next/previous item.
3. Back button should lead to the root view.
I've tried several approaches and no-one worked fine for me. The most right solution from my point of view is to create a middle controller between the root and detailed controllers to handle this next/prev redirects. But the main problem here is that switching from one detailed view to another the navigation pane stays the same, so it's not involved in the animation, whether Notes app work right in this case.
Could you point me how it' better to arrange controllers interaction in this case?
Thanks in advance. Sorry for quite big post, was trying to be as informative as possible.
Best regards,
Roman
I think the best implementation is this way:
Say you have a Note class where the data is stored.
You could have two view controllers, one with the list of notes and one with the details.
Both of these can be added to a navigation controller.
Then, when you want to switch to the next note, you retrieve that object somehow and assign it to your detail controller with a -setNote: call. That method will be responsible for changing what the outlets are displaying.
I've resolved this question - it's enough to pop current view and push new one, created for the next object in the list. The only think to remember is to save the reference to the navigation controller before the pop call, because after it self.navigationController becomes nil.
Yeah, it's misbehaving badly. Jongsma's reply is the best. In case you wanted to re-create controllers, I've found this to work:
[parent performSelectorOnMainThread:#selector(showMyItem:)
withObject:myNextItem
waitUntilDone:NO];
[self.navigationController popViewControllerAnimated:NO];
performSelectorOnMainThread delays execution of the method until the next run of the main loop, and by then the previous controller is removed already and navigation controller is in a stable state.