How Can I hide an info button from a subview? - iphone

I have a mainViewController and inside its nib file I added an info button, in which action is to flip between two subviews, subview A and subview B.
From mainViewController, under viewDidLoad, I'm inserting subview A. Here I notice that the info button is in front of the subview A, which is fine.
The problem comes that when pressing any buttons that are located within subview A's nib file, in which they add new subviews, the info button remains on front.
So, how can I add these later subviews on front of all parent view stacks, so the info button does not appear? or how can I hide the info button?

If I understand correctly, your mainViewController's view has two superviews: subView A and infoButton. You'd like to add subviews to subviewA that appear over the infoButton view?
The simple answer is that you can't make subviews of subviewA appear over the infoButton view. If you think of the view hierarchy as a tree, the renderer draws the views in a depth-first way. This means it draws subviewA, and all of subviewA's subviews (and so on) before it considers the infoButton view. If you want a view to appear over the infoButton view you need to add it as a sibling of infoButton after infoButton in the main view's subview list.
If you'd like to hide the infoButton, you can simply set the hidden property to YES, and then set it to NO when you want the infoButton view to reappear, of course.
Depending on what you're doing with subviewA, you might consider using a modal view controller or a navigation controller to manage the views that you add when the user interacts with subviewA.

Related

Display whole ViewController within another ViewController's view

Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.
I'm doing this:
HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];
HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = #"Title" won't work.
Thanks!
You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.
(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)
One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).
Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.

Seeing a ViewController behind the displayed one

Is it possible to view the viewcontroller behind the displayed one? I have a viewcontroller with a scrollview, which has imageviews added as subviews and would like the view that presented this viewcontroller to be visible behind the presented view controller.
I have set all the views, the viewcontroller view too to have a clear color background, but still there is a black background. when I dismiss the viewcontroller, I see 2 layers being dismissed. one has alpha dropped, the other not.
Is there an easy way to make this effect possible?
Its not possible. When a new view controller is pushed or presented as modal view, the previous view controller will be removed from the display(may be UINavigationController/iOS hides it). The rule is only one view controller would be visible at a time. So you will see the color of your window(the black color you've mentioned) in the background.
What you could do is make a screenshot before displaying the other controller. and send this image to new controller to be displayed as background.
This will only work for static content, but you could do something like the curl display.
You can do this but the truth is what EmptyStack says.
You can use setFrame of the subView and add it on the viewController. Also use below method to set the index of the added View. By default currentView has Index 0.
[self.view insertSubview:myView atIndex:0];
or you can try below methods as per your logic
insertSubview:aboveSubview:
insertSubview:atIndex:
insertSubview:belowSubview:
addSubViews:
bringSubviewToFront:
removeFromSuperview:

iPhone Dev - Scrolling to a new position in a tableview that is currently off-screen

Say for example I have a tab bar controller where one of its views is a tableviewcontroller, and another one is some other view. The other view has a button in it that when pressed, should make it so the tableview (which is not on the screen while you're pressing the button) repositions itself so that some specified cell is now the top one being displayed when the tableview is again displayed.
My question is this: can I just call [myTableVC.tableView scrollToRowAtIndexPath:someIndex] from inside the other class when the button is pushed? Or does the view actually have to be on the screen when scrollToRowAtIndexPath is called for it to change the top cell that will be displayed?
You may be able to, but you probably shouldn’t—calling view or tableView on an offscreen view controller may cause its view to get loaded into memory unnecessarily. Just set a property—a CGFloat or whatever—on the view controller for the scroll position that it should be at when it appears, and scroll to that position in the controller’s -viewDidLoad or -viewWillAppear:animated:.

iPhone iPad UIView controller popup centered

My application is for iPad.
I have a UIViewController as the main view of my application.
I have an UIView at the bottom as a footer, and inside 3 UIView (subviews).
My 3 subviews in the footer banner load for each a different UIViewController and display the view of this controller into their view.
I would like when I click on a button into one of this subview (button that belongs to my UIViewController, with a 240x162px view), to make the subview disappear and display a centered popup (500x350px) with an animation into my main view.
To show you an example, WeatherBug for iPad has what I want, when you click on a block on top, the little view flip and a zoom effect is done, that display a centered uiview with more content.
Please tell me where I should look for!
Thank you,
Use the delegate pattern. Assign your "root" view controller as the delegate for your "footer" view controller. When the button is tapped (no clicking on the iPhone), the "footer" view controller will hide the banner, then call a delegate method to handle the tap action; in this case, the "root" view controller then shows your centered popup. When the popup is done, the "root" view controller then tells the "footer" view controller go show the banner again and go back to normal.

adding a footer overlay to the main window, to be shown over every subview, in an application using navigation controller

I'm working on an iPhone app where I'm using a navigation controller (UINavigationController) to navigate through the various child views, and I would like to add a uiview to either the main window or the navigation controller, as a footer overlay that shows up on top of all the child views. I've tried this through interface builder, and programmatically, but nothing seems to work.
Working in interface builder, I've tried adding the footer to the bottom of the main window, and decreasing the height of the child views so the footer would show up, but the children seem to resize to fill the whole window. I've tried playing with some of the options, like 'wants full screen', 'resize view from NIB', tried to resize the navigation controller and couldn't. Same problem when I try to add it programmatically instead.
I can add a toolbar to the navigation controller in interface builder, is there a way to add a UIView instead? Or even attach a UIView to a toolbar? I'm sure there's a simple way to do what I'm trying, I'm hoping someone out there has had a similar experience.
Thanks!
If you want to have a toolbar sized custom view you can just position it where the toolbar would be and add it to the window as a subview above your navigation controller. Then you don't have to worry about autoresizing ruining your fun, you'll just always be drawing your view over the navController's toolbar.
[myWindow insertSubview:newView aboveSubview:myNavController.view]
Just make sure you adjust the size of your view if you want to respond to device rotations, as the toolbar size changes then.
You may also have success creating a view hierarchy that looks like this:
UIWindow
Subview 1: Custom view which holds app content
Subview 1a: UINavigationController with your main view as its root view
Subview 2: Custom view which holds your footer content
Subview 2a...2z: whatever views you need inside your footer
That way you can make your footer whatever height you want. Just set the appropriate autoresizingMask properties on your window's two subviews so that you can ensure proper positioning as well as respond to interface orientation changes automatically.