I want to present a modal view with a UIscrollView as the content of the view. How would I do this?
As always, do a viewController and set it's view as the scroll view (in load view)
self.view = aScrollView;
and present it modally : (in your first viewController)
[self presentModalViewController:theViewController animated:YES];
Create a standard UIViewController, and give it a UIScrollView as its view member. Then use -[UIViewController presentModalViewController:animated:] on your current (visible) view controller. This will (by default) slide the new one in from the bottom.
Related
I have two view controllers named as firstvc, secondvc. I have a subview in the firstvc, it looks like a form which has textfields. In firstvc there is a button to maximize that subview.
When I click on that, I am adding that subview to secondvc and I am presenting secondvc view in UAModalPanel. If I close that secondvc, firstvc should appear. My problem is that I was unable to retain that subview. It means when I close secondvc, firstvc subview is disappearing.
Can you suggest how to retain that subview between two view controllers?
-(IBAction)maximize:(id)sender
{
UIViewController *newview = [self.storyboard instantiateViewControllerWithIdentifier:#"second"];
[newview.view addSubview:subview];
UAModalPanel *modalpanelobject = [[UAModalPanel alloc]initWithFrame:self.view.bounds];
[modalpanelobject.contentView addSubview:newview.view];
[self.view addSubview:modalpanelobject];
[modalpanelobject showFromPoint:self.view.center];
}
I am the developer behind UAModalPanel. The panel does nothing to mess with the view hierarchy of views that are not added to the contentView so this problem probably would exist even without it. I would subclass the first controller's view and place a breakpoint in the dealloc and removeFromSuperview methods to see what is removing the view, when and why.
Look,
The concept is
There are three view you can consider.
Child View (ScrollView in your case)
Parent View 1 (GridCell)
Parent View 2 ('Maximized View)
What you are doing is when
1.You are maximizing the Child view
At that time you are taking the Child View from Grid Cell to Maximized View.
2.Now in reverse when you are closing the Maxized View.
Correct:At that time you SHOULD take the Child View from Maximized View to Grid Cell.
for doing that you can not find your Child View in Grid Cells.
Best Regards.
I have a UIViewController named LoginViewController, and it is a rootViewController in the AppDelegate. In the LoginViewController, I have two buttons: Login and Enroll.
When I tap Login, I assign a TabBarController as the rootViewController, then show the TabBarController. However, now I think I need to add another UIViewcController as a subview when I tap Enroll. I tried the following:
[self.view addsubview:viewcontroller.view];
But the problem here is My ViewController's view.top is pinned about 20 pixels below the top of the screen. I think there is an issue with the status bar, but I can't figure out how to fix it.
I think that I need to add my ViewController as a subview to the LoginViewController, then redirect from there to different views. Can someone please suggest other options?
Try to set frame to your enroll screen object then add it as a subview to loginview.
Ex:
[enrollViewcontroller.view setFrame:CGRectMake(0,0,320,440)];
[self.view addsubview:enrollViewcontroller.view];
You should not make a UIViewController a subview of another UIViewController's view. What you likely want to do if treat the subview as a normal UIView (if not both of those views) so that you only have one UIViewController on screen and it occupies the entire screen.
More here: How to add an UIViewController's view as subview
Instead of adding a UIViewController as a subview to another UIViewController, I have decided to present my ViewController as a ModalViewController using
[self presentModalViewController:myViewController animated:YES];
I have a UIViewController, and it has another UITableViewController as subview.
Table view is not visible, but in sometime it is visible by user's action. (for example, search table view.)
so, two new controller has no relation actually, (but UIViewController has UITableViewController as member variable), but only its view has parent - subview releation.
In this situation, user click the cell item in the table view, I have to push new view controller to navigation controller.
but only parent UIViewController is in navigationController, subview UITableViewController is not.
so code
[self pushViewController:viewController animated:YES];
fails in UITableViewController.
I solved this problem by passing navigationController instance of parent UIViewController to UITableViewController as property named parentNavigationController, and I called
[self.parentNavigationController pushViewController:viewController animated:YES];
instead.
It is solution that is not so bad, but I thinks it is some confused, I want to know is there more clearing solution.
How do you programming in this situation, friends?
I think parent-sub view relation of two view controller is confused, in the first. Is it better if I manage two views in one viewController? If then, view property of UITableViewController can be not table view? (and that view has table view as subview)
Thanks for your support, in advance.
Actually the concept is to push view controllers to the navigation stack of navigation controller. And UIViewControllers can only present modal view controllers, they can not push view controllers. So, sending pushViewController message to self(which is a UIViewController) is wrong. You can push a view controller using [self.navigationController pushViewController:anotherViewController];
In UITableViewController controller use self.navigationController instead of self.
[self.navigationController pushViewController:viewController animated:YES];
I have a simple uiviewcontroller with 4 buttons. Every buttonclick event loads a different image on the view. However for the 4th button i want to launch a navigation controller based uiview with a uitableview. The table view can then have 3 levels which define the settings for the application.
On selecting a row in the uitableview on the 3rd level i need to return to my main view with the selected row index.
How can i add a navigation based view which will be launched on a button press event and the first view of the uinavigationcontroller should compose of a back button which will close this navigation view and return to main view.
TIA,
Praveen S
Edit:
My first(home) view does not need a navigation bar. The view launched from the home view should however consist of a navigation bar with back button.
if(nxtv12==nil){
nxtv12=[[v12 alloc] initWithNibName:#"v12" bundle:nil];
}
[self.navigationController pushViewController: nxtv12 animated:YES];
and for coming back to home.
[self.navigationController popToRootViewControllerAnimated:YES];
Create a UINavigationViewController object in the current UIViewController (or use self.navigationcontroller) and push the new UIView into the navigation controller. To come back to the same view, use popToRootViewControllerAnimated in the new UIView class.
I have a problem with transitioning between views in different ViewControllers.
Here is the situation:
My App is a TabBarApplication done with IB which contains a UIViewController for each Tab. The UIViewController (PlayerTabViewController) of the first tab contains another UIViewController (PlayerCreationViewController) to manage a view that will be added as subview.
I was able to add the subview using
[self.view addSubview:playerCreationViewController.view];
In the PlayerTabViewController.
The problem is that from the subview I have to return to the parent view and reload it because it contains a tableview that must be refreshed.
Using [self.view removeFromSuperview]; in the PlayerCreationViewController I can switch back to the parent view, but I'm not able to reload the tableview or do other actions.
I tried to implement the -(void)willRemoveSubview:(UIView *)subview method in PlayerTabViewController but it seems the function is never called.
Do you have an Idea of what am I doing wrong?
you are using wrong method to go on next view. just use navigation view controller to switch from one view to another view.
create a object of view
PlayerCreationViewController *playerViewController = [[PlayerCreationViewController alloc] initWithNibName:#"PlayerCreationViewController" bundle:nil];
[self.navigationController pushViewController:playerViewController animated:YES];
[playerViewController release];