iPhone SDK moving a view and its subviews to back - iphone

I have an application with multiple views that contain subviews. I know that you can hide or make visible a view and its subviews by setting the hidden property to YES or NO. However with a number of views, to use the hidden property requires keeping track of what view is being displayed. I thought I could use sendSuBViewToBack: to hide a view and moveSubViewToFront to make it visible. However, these methods appear to only act on the specific subview and not its child subviews. For example, a view with a couple of labels on it, when sent to the back, the labels remain visible.
Is there any way to make this behavior work besides using the hidden property?
Thanks,
Jim

UIViewController seems like what you're looking for. Or rather, what you should be looking for.

I'm not quite sure what exactly you're having trouble with here. As long as you're keeping track of each "container" view (perhaps using a #property), you should be able to show/hide them on demand using a method in your code (which can be as simple as hiding all container views, and then showing the one you desire).

Related

How to move other uiobjects relatevely when a new view is shown in the main view

I am developing an iPhone app,which contain a page consisting of three UISwitch. When the the UISwitch is in On state the app displays a small view below the switch. This works for all three switches. But the problem is that the small views displayed will overlaps if I switch on two switches at a time. Is there a way to shift all the other view relatevely when those views are displayed..
Thanx in advance....
This sort of problem is exactly what auto layout is good for. When you add a new object, remove and regenerate your constraints (you may only need to change a couple, depending on what it currently in place), then call layoutIfNeeded on the superview. If you do that inside an animation block, it will even animate into the new layout for you.
Its a bit late but this may be what you looking for.
CollapseClick

Best way to show a small view/dialog over an existing screen?

All my views/pages in apps so far have been full screen UIViewControllers that i push and pop from the stack.
I see some apps create a new view/window that appears about the 1/3 the size of the full screen on an iPad, containing tables of items to select or other UI elements. They are commonly used to allow users to filter the current view they were on.
Seeing them in apps, I guess that they are just adding a UIView to there current screen and change its frame depending on where on the screen they want it to appear.
Or am I wrong? Is there another/better way to do this?
I guess you are talking about UIPopovercontroller. There are several tutorials to build the same.check this. Hope that helps you.
It's a little unclear from your question what the view looks like.
If the view is "attached" to a UI element (has a little triangular arrow connecting it to, e.g., a button) and goes away if you tap outside it, then it's a view presented from a UIPopoverController.
If the view overlays everything and dims the content behind it, is likely a model view controller presented with a presentation style of ether page sheet or form sheet.
Both are common and easy to set up. See the class documentation I have linked.
In most cases, these are probably normal modal view controllers whose modalPresentationStyle property is set to either UIModalPresentationPageSheet or UIModalPresentationFormSheet.
Yes you can make your own UIViews and just add them as subviews. Another option for iPads specifically is with the UIPopoverController class.

Moving and existing UI on a UIScrollView

I have some xibs with all sorts of text controls (UITextFields, UITextViews). Since the keyboard obscures some of these text controls when text input starts, I followed Apple's guideline for managing content located under the keyboard.
In short, the solution involves moving all interface elements on a UIScrollView. Doing it from Interface Builder I simply add a UIScrollView on the view, make it the size of the view, send it to back and link it's referencing outlet to the file's owner view property.
In IB this all looks fine, and the UI elements appear above the UIScrollView. However when I run the program, the UI elements are nowhere to be found. Their IBOutlets however seem to get initialized so it looks like they are actually constructed. I've tried to set the UIScrollView alpha to 0 to see if they are placed behind it but I still can't find them. New items that are added to the UIScrollView however, seem to work fine.
This leaves me with the not so great option of rebuilding all my xibs where I need to do this change. It kind of looks like an Interface Builder bug to me. What do you guys think?
Well I've found a solution. It goes like this:
Drag a UISCrollView in IB's main window (where we have the File's Owner and First Responder objects).
Rescale it to the size of the initial view
Drag and drop everything from the original view to the scroll view.
Link the scroll view's referencing outlet to the file's owner view property.
Delete the old view from IB's main window.
#MihaiD
use tableview.contentOffset=CGPointMake(x,y);
I don't know if you really need a UIScrollView. See this question on SO it slides the parent view up.

iPhone/Obj-C: Accessing a UIScrollView from a View displayed within it

I'm writing a simple iPhone app which lets a user access a series of calculators. It consists of the following:
UITableViewController (RootViewController), with the list of calculators.
UIViewController + UIScrollView (UniversalScroller), which represents an empty scroll view - and has a 'displayedViewController' property.
UIViewController (Calculators 1-9), each of which contains a view with controls that represents a particular calculator. Each calculator takes 3-5 values via UITextFields and UISliders, and has a 'calculate' button. They can potentially be taller than 460px(iPhone screen height).
The idea is:
User taps on a particular menu item in the RootViewController. This loads and inits UniversalScroller, ALSO loads and inits the UIViewcontroller for the particular calculator that was selected, sets the displayedViewController property of UniversalScroller to the newly loaded calculator UIViewcontroller, and pushes the UniversalScroller to the front.
When the UniversalScroller hits its 'viewDidLoad' event, it sets its contentSize to the view frame size of its 'displayedViewController' object. It then adds the displayedViewController's view as a subview to itself, and sets its own title to equal that of the displayedViewController. It now displays the calculator, along with the correct title, in a scrollable form.
Conceptually (and currently; this stuff has all been implemented already), this works great - I can design the calculators how I see fit, as tall as they end up being, and they will automatically be accommodated and displayed in an appropriately configured UIScrollView. However, there is one problem:
The main reason I wanted to display things in a UIScrollView was so that, when the on-screen-keyboard appeared, I could shift the view up to focus on the control that is currently being edited. To do this, I need access to the UniversalScroller object that is holding the current calculator's view. On the beganEditing: event of each control, I intended to use the [UniversalScroller.view scrollRectToVisible: animated:] method to move focus to the correct control. However, I am having trouble accessing the UniversalScroller. I tried assigning a reference to it as a property of each calculator UIViewController, but did't seem to have much luck. I've read about using Delegates but have had trouble working out exactly how they work.
I'm looking for one of three things:
Some explanation of how I can access the methods of a UIScrollView from a UIViewController whose view is contained within it.
or
Confirmation of my suspicions that making users scroll on a data entry form is bad, and I should just abandon scrollviews altogether and move the view up and down to the relevant position when the keyboard appears, then back when it disappears.
or
Some pointers on how I could go about redesigning the calculators (which are basically simple data entry forms using labels, sliders and textfields) to be contained within UITableViewCells (presumably in a UITableView, which I understand is a scrollview deep down) - I read a post on SO saying that that's a more pleasing way to make a data entry form, but I couldn't find any examples of that online. Screenshots would be nice. Anything to make my app more usable and naturally 'iPhone-like', since shuffling labels and textboxes around makes me feel like I am building a winforms app!
I've only recently started with this platform and language, and despite being largely an Apple skeptic I definitely see the beauty in the way that it works. Help me solve this problem and I might fall in love completely.
Dan
If you have the particular calculator view, you should be able to get to the scroll view via the superview property (though there might be more than one intermediate view, so you might need the superview of the superview).

Iphone View explanation in detail (View, Superview, etc)

I'm looking for an in-depth breakdown/explanation of the iphone's view usage. Like, what controllers have what types of views, how they relate (child <> parent), how they can be nested, added and removed, etc.
Preferably something with some pictures would be nice too (I'm a visual learner).
But yeah, in-depth, technical, explanations of the iphone view system when used in IB/Obj-c would be awesome.
Also, feel free to give your breakdown or post to resources and I'll do the research.
Thanks
EDIT:
Ok, I'll be more specific. Is the View a stack - is it a queue? What does it look like when I call addtosubview?
What happens if the view isn't a full UIView, but say a smaller UI Control - will it be visible?
Say I have a UIView with a UITabView (2 items) and one content view is a UITtableView.
What's the parent view? What is the order of the children? Is that all dependent on how I add them to the view? In this case, the UITabBar control takes care of handling the views when I select the button.
When I call insertSubview how do I know what index to position it at?
This will be a good place to start (go from here to UIViewController and others that seem relevant). A UIView can contain many subviews of any type (they all inherit from UIView). To nest views, you add the subview to the superview [superview addSubview:subview]. You should also read up on Model-View-Controller.
Edit:
This SO question might also shed some light on the matter.
Edit edit:
Best I can do to answer your questions:
UIViews have an iVar subviews which is an array of subviews. Each of these also has such an array and can contain UIViews.
I assume you mean not full screen, generally, the topmost view is a UIWindow, and to this you add any UIView subclass you like, such as UISlider.
Your UIView has a subview UITabView, I don't know specifically, but I would guess it has two subviews, one of which is visible at a time, and one of these is the UITableView. Order is dependent on the order you add them in, and they will overlap each other depending on this order, but it can be changed with sendSubviewToBack and bringSubviewToFront.
If you want a specific view order, you're probably better off using insertSubview:aboveSubview: and the equivalent below, rather than at index.
Hope some of this helps.
Ok, I'll be more specific. Is the View a stack - is it a queue? What does it look like when I call addtosubview?
I like to think of it as a tree. The window is the root node, and it has any number of subviews. Those subviews can have any number of their own subviews, going down as far as necessary to create the full interface. The addSubview and removeFromSubview methods manipulate a view's "children".
What happens if the view isn't a full UIView, but say a smaller UI Control - will it be visible?
My understanding is that everything on the screen is a subclass of UIView, even the UIControl objects. Therefore, they behave mostly the same.
Say I have a UIView with a UITabView (2 items) and one content view is a UITtableView. What's the parent view? What is the order of the children? Is that all dependent on how I add them to the view? In this case, the UITabBar control takes care of handling the views when I select the button.
I'm not sure: David's answer has more info that should help.
When I call insertSubview how do I know what index to position it at?
I wouldn't worry about it: most of the time you just want addSubview and you won't care about the internal order.