My view hierarchy containing the view from a MPMoviePlayerController vanishes the moment I present a Modal View Controller.
Instead of displaying a view with a movie and controls it depicts an earlier subview beneath it. I checked the subview array of the main view controller and all views including the movie player view exits.
Forcibly adding the movie player view after the modal view controller is done does not bring movie player view back on top.
Would welcome any suggestions/thoughts ?
your problem isn't specific to the MPMoviePlayerController. any time you present a modal view controller, all of the views from other view controllers beneath it disappear.
try it out with just a couple of simple view controllers.
in the app delegate, set your window background color to red:
[self.window setBackgroundColor:[UIColor redColor]];
then add a view controller with a green background:
UIViewController *vc = [[UIViewController alloc] init];
[[vc view] setBackgroundColor:[UIColor greenColor]];
self.window.rootViewController = vc;
finally, create another view controller with a transparent background, and present it modally:
UIViewController *vc2 = [[UIViewController alloc] init];
[[vc2 view] setBackgroundColor:[UIColor clearColor]];
[vc presentModalViewController:vc2 animated:YES];
you'd expect to see the green VC through the clear VC, but instead you see red (ie, you see the window).
Related
I have inherited an iOS app that has not been maintained since iOS 3 era. The app relies on a web view to display some data. One of the feature is displaying the video in a full screen mode. What the client needs is a video reacting to the device rotation but all other views should be only portrait.
I've managed to figure out all the window.rootViewController and shouldAutorotate changes. I get the app to rotate only when I want. The problem I am facing is the video rotation 'too much'.
If I rotate the device left, the video rotates by 180 degrees (it goes into upside down orientation). Rotating back to the right causes the view width to shrink by half but the orientation is correct. I am not quite sure where the problem could be.
Anyone had similar issues?
I did have the same problem by inheriting a project. In my case, the application is navigation based, and the problem was that the main UINavigationController's view was being added as a subview of an UIViewController's view.
So, initially I had this code on my application:didFinishLaunchingWithOptions::
self.viewController = [[MyViewController alloc] init];
self.window.rootViewController = self.viewController;
and this on MyViewController's viewDidLoad:
UINavigationController *navController = [[UINavigationController alloc] init];
[self.view addSubview:navController.view];
Then I simply changed my application:didFinishLaunchingWithOptions: to this:
self.viewController = [[MyViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = self.navigationController;
I hope this helps you!
New to iOS dev. Kindly correct me if i am wrong?
I have a UIWindow, and rootviewcontroller is :
#interface ViewController : UIViewController
{
IBOutlet UIButton *but;
}
#property (nonatomic, strong) UIButton *but;
-(IBAction) butButtonPressed;
#end
ie: If i make this Viewcontroller as a root view controller, the UIView that is available in the ViewController is displayed. Understood.
I have created a new class inherited from UIViewController, and along with its .xib file.
So xib file name is : view1.xib,
My Objective is to display this view when the button is pressed.
Now i have created a button and button press invokes butButtonPressed. Inside of butButtonPressed, i did the following.
myViewController *vcontroler = [[ViewController alloc] initWithNibName:#"view1" bundle:nil];
[self.view.window addSubview:vcontroler.view];
Application crashes. What am i doing wrong ? Kindly point out.
This...
[self.view.window addSubview:vcontroler.view];
...is a really bad strategy (and I seriously wish I knew where people are finding it as a way of showing views). If you create a view controller, you should use it rather than just treating it as a temporary container that you can rip views out of.
If you want vcontroler to look like a child of your first controller (and you have a UINavigationController), use pushViewController:animated:. Otherwise you can show it as modal with presentModalViewController:animated:.
If you only want to add a view to the existing display, put the view in ViewController's hierarchy and show/hide it.
If you absolutely must have it as a sub-controller of ViewController then you need to keep a reference to it and manage its lifecycle inside the owning controller.
How to add UINavigationController to xCode Tab Bar Application Delegate?
My structure is based on xCode Tab Bar Application Delegate, with 2 tabs, First View & Second View respectively. For First View, I added a UITableView. I just want to make use of UINavigationController function [self.navigationController pushViewController:animated:] to push a subview and allow a navigation bar to be shown in subview. After pushing the subview, the tab bar must still be there.
Sounds simple, but I have no idea how to achieve it. Please help.
I started with a Window-based template instead and did this to achieve the same thing.
I created my NavigationControllers and TabBarController in my app delegate manually.
In your:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add this:
//Seeting up the Navigation controllers and pushing our TableView controllers.
UINavigationController *unvc1 = [[UINavigationController alloc] init];
UINavigationController *unvc2 = [[UINavigationController alloc] init];
[unvc1 pushViewController:someViewController1 animated:NO];
[unvc2 pushViewController:someViewController2 animated:NO];
[someViewController1 release];[someViewController2 release];//Releasing our TableView controllers.
//Setting up the TabBar controller and pushing our Navigation controllers.
UITabBarController *tbvc = [[UITabBarController alloc] init];
tbvc.viewControllers = [NSArray arrayWithObjects:unvc1, unvc2, nil];
[unvc1 release];[unvc2 release]; //releasing our Navigation controllers.
I hope this helps.
I did this using presentModalViewController:animated . I added tabBar Controller in the modalView. In the method didSelectRowAtIndexPath use this presentModalViewController:animated .I might not be perfect but I had the same problem, but now my app works as I need.
I am creating an application which displays map using MKMapView control. I have a button on the map that takes me to different view (information view) using the following code:
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
self.view = infoViewController.view;
Now after going to the information view I want to go back again to the main view which displays the map without having to loose anything. Is NagivationControlller my best option to use in this scenario?
Try this,
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
[self.navigationController pushViewController:infoViewController animated:YES];
[infoViewController release];
once you push viewController back button is available to come back to rootViewController.
I have implemented MPMoviePlayer functionality to play in landscape mode in iOS4- by reading information on other posts - thanks stackoverflow!
Basically I have a list of videos in tabular view and from that I can navigate to each video.
Problem I am facing is the video does play in fullscreen (landscape) however the top title bar and bottom navigation bars continue to be visible above the movie. I have tried to hide the bottom tabbar
[self.navigationController setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:MstvideoplayerView animated:YES];
as well as tried to bring the movie subview to front
[[mpMoviePlayerControllerObj view] setFrame:CGRectMake(0, 0, 480, 320)];
[[self view] bringSubviewToFront:[mpMoviePlayerControllerObj view]];
mpMoviePlayerControllerObj.controlStyle = MPMovieControlStyleFullscreen;
However the top title bar (from movie list view) and bottom navigation bar still remain - on top of the movie player window.
How do I hide/get rid of these 2?
If you call the UIViewControllers method
presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animatedwith the MPMoviePlayerViewControllerinstance, it should present the movie player fullscreen