how to restore view to view did load - iphone

i am using a view that displays multiple items depending on user input and i would like to when i press a button to be able to go back to the first view generated in the view (viewDidLoad).
I tried numerius methods such as adding an action to a selector to load a -(void) that reloads the view however that crashes too.
I havent been able to find a resolution to this problem for quite some time
Thanks

You may need to post some code to get a better answer. I'll assume that you are showing views on your original view, and some of them cover your original view. If this is the case, the original view still exists, and you simply need to remove the views that were added later. If they were presented as a modal dialog, remove with [childViewController dismissModalViewControllerAnimated:YES]. If you added them with [self.view addSubview:childView], remove them with [childView removeFromSuperView]. If you are using a navigation controller, you'll similarly need to pop your child view. Instead of adding and removing views you could hide or show them if they should only be initialized once. If you want a more specific answer, reduce your code to the minimum required to make it happen and post it!

Related

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:

iPhone duplicate/copy a viewcontroller entirely

I have a view controller with user content like text/images/location data and i would like to duplicate the viewController and present it modally (presentModalViewController) when the user taps the edit button. The reason for doing this is because i want it to be clear that the user is entering the edit mode by using the transition/animation that comes with a modally presented controller.
Does anybody knows how to duplicate an entire viewController + its view? i don't want the overhead of reallocating the entire viewController. I tried a couple of things, but i haven't had any luck.
Any help/information would be welcome.
That sounds a little impractical. You could make an image of the current screen contents, present that using whatever animation you like on top of everything, and then remove it?
Or make other changes to your view (rearrangement of views, appearance of other controls, changes of colour) in your viewController's setEditing:animated: method.

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.

UISegmentedControl underneath UINavigationBar, WITHOUT scrolling

Ok so ive been at this problem from a day or so now, seems to be a fairly common problem amongst new iOS devs. However, ive search google, appledev, stack overflow etc.
However, ive had trouble finding the correct solution. No where has clear answers.
I need the segmented control to either change the tabledata source or show a new view entirely, either would be fine.
At the moment, i have a work around solution where i put the segmented control inside a tableheader, this would work fine, but i dont want the segmented control to scroll with the table cells.
Im trying to have it static and unscrollable, just like the Navigation bar.
Ive tried a few option in interface builder but neither of them work, either they dont show up or i get a crash because it couldnt find the table view.
Although, i do know it has something to do with putting a view inside a view?
If anyone has a spare moment to write a quick but detailed guide, i would be very thankful.
edit
Attempt 1:
in IB...
View
-> Tableview (tableview inside the parent view)
creates this error
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "EventsViewController" nib but didn't get a UITableView.'
First of all you will need a single controller which will contain the segmented control, table view and other elements which you want to add.
Since there is a single controller for your application, any change in the segmented control can be captured in it. Once you capture the event you can decide whether to reload the tableview by updating the tableview or load a new view.
This new view can also be loaded as a modal view or as a new view to a navigation control or as a subview to the current view. (the call is left to you).
The advantage will be the segmented control and table view will be part of a UIView and scrolling one will not scroll the segmented view out of sight. Other advantage will be the new view will be loaded on top of the current view. You can have delegate methods to handle the back press event on the new view. You can also get data from the new view to a single controller.
UIView
--- Segmented control(you can wrap this into a seperate UIView
--- UITableView (it can also be wrapped into a seperate uiview )
--- Other widgets
Now you can have a single view controller controlling the above Main UIView. Hope this helps you. I have used a similar approach in one of my apps.
What you can do is have a segmented control basically change the table data source. Basically, set the action hitting either segment as [myTableView reloadData];. Then, in your data source methods, put some if statements up. For example, under numberOfRowsInSection, say: if (mySegmentedControl.selectedSegmentIndex = 1) //2nd button, use this array. Get what I mean?
This way you can use one view controller to with basically two (really one) table.

Where should I save a user's work when using a table with detail view pattern?

I've implemented workflow that uses a table view and a detail view with a navigation bar. I have been using the viewWillDisappear: message on the detail view to save the user's work, which I like because it makes sense intuitively, but it also gives the chance to set a cancel flag if the user wants to discard their work.
However, when I add the ability to take a picture to the workflow, it means that the viewWillDisappear: now is called both when the user goes back to the table and when going to the camera view. Is there a technique or method I can implement to make it so that the user's work is saved when going back to the table, but half finished work isn't saved when going into subviews?
You can check if a the detail view is being popped in the viewWillDisappear: method. The solution would be something similar to the answer to this question:
viewWillDisappear: Determine whether view controller is being popped or is showing a sub-view controller