UINavigationController 'menu' - iphone

I am trying to create a 'book style' interface. I have a plist which holds an array telling me which view controller is the next 'page'. So I check that, push the page onto the stack and fill it with info from the plist.
I also need a 'menu' button though so that users can quickly jump between pages. This is pretty simple but if the users jumps form page 1 to 3 for example and then uses the back button it will obviously pop back to 1. I need it to pop to page 2 though.
What is the best way to accomplish this? I have tried popToViewContorller: animated: but get the error telling me that the vc I'm trying to pop to does not exist.

Ok what you need you need to push each page for reaching your desired page means
suppose you want to go 4 page from 1 page then what you need set a integer variable(make it property in app delegate class) according to you view number.
then push next view according to your plist then check this your desired page (by checking your page number save in property and current page number). if yes then remains there otherwise push other one.(this will done viewDidLoad of each page).
Remember when you got your desired page then set that bool variable to NO;
For managing page number add one more thing in plist thats page number with that and then make your logic.

I dont think u can do it by poppingViewControcollers.Its that in ur navigationController.viewControllers array u will just have page1 at zero index & page3 at 1 index.When u do popToViewContorller: animated: its takes you to just immediate previous navigationController viewController that its being loaded like in ur case its page 1 is loaded before page3.

Maybe what you want is not a UINavigationController at all? It is designed to manage a stack of view controllers, but what you want is a list of controllers.
You can make your own custom subclass of UIViewController that manages an array of sub view controllers, populating a UIScrollView with the views from the managed view controllers.
This way the UIScrollView can:
Handle paging for you
Back, forward and even jump is simply a matter of setting the contentOffset.
You say you have all the view controller in a plist, so they can not be too many. So no need to worry about dynamic creation and complex life-cycle management of the managed view controllers.

Related

iOS 10 go back to root in nav stack with parameters

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

Swift - Reuse the old instance of view when switch between Views and Passing data over views

I am trying to create a simple app and here is how it works:
When the user clicks the button "Picking", it'll show a tableview. And when the user selects a row in the table view, it will show the first view and display the data on the label.
I have 2 problems:
Every time I click the button "Picking", a new instance of the table view controller gets created; but does not reuse the existing one. How can I make it reuse the old one?
I want to pass the selected data to the root view. I tried by creating a segue to show the root view when user selects a cell and then passing the data on prepareForSegue method. But, I faced the above problem of memory leak. How do I pass the data between screens without leaking memory?
It sounds like you may be making a circular view hierarchy. When you tap on the cell in the table view, if you're pushing a new instance of the first VC, that is the wrong way to do it IMO.
Instead, you should pass the data back to the first VC then dismiss the second VC. Then, when you tap on the "Picking" button again, it's a new instance of the table view but your previous instance has already been removed from memory.
This allows for the smallest amount of memory to be used at any given time. When the table view controller isn't on the screen, it doesn't need to be in memory.
IMO, the best way to pass data up a navigation stack is to use a protocol and delegate. It's similar to how Objective-C protocols and delegates worked if you're familiar with that. Here is Apple's documentation on both. The delegate section is about 1/3 the way down the page.
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html

iPhone Structure ViewController

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:

iOS tab bar object holder

I am new to Obj-C so I will be happy for any best practice idea or something.
I have a table view with some objects. When any object is selected I would like to open an object detail view with tabs. These tabs divide the object properties to some logical groups.
But it still describe one object and I would like the user has an experience when creating the new object he can switch between tabs and change the values without any saving data until the save button (common for all tabs in navigation bar) was clicked.
Thanks for any help.
Not quite sure what you are asking for. I think you can use UINavigationController to lead the user to the detail screen, in the detail screen use UITableView to display your object detail. If you want to group them, you can set the tableView style to Grouped.
If you are asking for something else, please provide more details.
To be idiomatic with the iOS experience, displaying the Tab Bar should be a modal dialog with a "Done" button then.
Create a UINavigationController and place the UITTabBarController as the root controller of it, then in the navigation bar of the root controller place 'Done' button.
Note that you must keep a temporary model of whatever you are editing in memory (I would suggest subclassing UINavigationController, adding a property for the object and passing a pointer to the object to all of the tab controllers), since the views containing the changed data can be deallocated at any time when they are not displayed to save memory.

How to switch to a TableView from a first View?

I'm working on my first app and I've issues on how to layout some of its logics.
Basically, what the app is supposed to do is to show a first screen when launched where user can fill in some values and press a button that opens a tableview which shows results. The first screen (view), outlets and connections are all working fine. The issue I'm having is how to leave this "home" search view and show the results to the end user on a table view. Right now, I've only 1 view with its related View Controler and this controller handles the tasks of taking user inputs and get results throughout a HTTP post request.
I need your guidance...Thx in advance
Stephane
Is there a reason that this all has to happen on one screen? iOS is set up to allow for this to happen very easily and (I think) attractively by using a UINavigationController and pushing in a new view controller (could be a UITableViewController or simply a UIViewController that contains a UITableView).
If you MUST have all of this take place in one view, Swastik is correct that it will require some view acrobatics. One way to do it attractively is to use the UIView animations introduced with iOS 4.
Here's Apple's UIView documentation: UIView Class Reference
Specifically, check out the CLASS methods of:
1. animateWithDuration:animations: (with or without completion:)
2. transitionWithView:duration:options:animations:completion:
Note that these methods will require you to learn a little bit about blocks, but it's worth it and I think blocks give tremendous power!
With the methods mentioned above, you could fade out your form and fade in your tableview, or maybe just move the form off-screen while the table view flies in. The possibilities are limited only by your imagination.
u can add a table in ur xib.Initially make it hidden, & when u need to show it unhide it & also if u want to update table's data , you can reload the data of the table.