completion:nil on presentModalViewController - ios6

When I set
[self presentModalViewController:Facebookcontroller animated:YES];
to
[self presentViewController:Facebookcontroller animated:YES completion:nil];
to erase the presentModalViewController:animated is deprecated: first deprecated in iOS 6.0
pops another warning:
Instance method '-presentModalViewController:animated:completion:' not found (return type defaults yo 'id')

Are you sure self is a UIViewController in this context. You can call this code only from another UIViewController.
Make sure you initialize the Facebookcontroller class first, you cannot pass just the class. Facebookcontroller *facebookController = Facebookcontroller alloc] init];
For iOS 6 use:
[self presentViewController:Facebookcontroller animated:YES completion:^{
//Do whatever you want to do when the controller 'Facebookcontroller' is presented.
}];
or
[self presentViewController:Facebookcontroller animated:YES completion:nil];
You can find the reference here.

Related

Can't dismiss AVPlayerViewController in iOS16

Since iOS 16 made changes to AVPlayerViewController, the dismiss button ('x') in the top left corner simply doesn't work. The 'tap' is normal, but it feels like the UIButton target doesn't do anything. I feel like I'm missing something obvious. Is there a delegate method or setting that needs to be used for it to work? It all worked perfectly before iOS 16. Implementation below:
AVPlayerViewController *vc = [[AVPlayerViewController alloc] init];
vc.player = [AVPlayer playerWithURL:[NSURL URLWithString:videoInfo.VideoURL]];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:vc animated:NO completion:nil];
Using animation. It can be fixed but I don't know why.
[self presentViewController:vc animated:YES completion:nil];

IOS: set a property in iOS7

In my app I have this property (and its #synthesize in .m)
#property (nonatomic, strong) IBOutlet UILabel *titleHeader;
in a secondViewController.
The problem is that in iOS 7 if from firstViewController I do:
[secondViewController.titleHeader setText:#"title"];
it don't work, in iOS 6 it work.
why?
EDIT
I do it:
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];
The views of secondViewController have not been loaded yet when you set them.
You can verify this by querying for the value of secondViewController.titleHeader after pushing the view controller to the navigation stack.
As a fix, you can declare a property in secondViewController
#property (nonatomic, strong) NSString *titleHeaderText;
then set that property instead of secondViewController.titleHeader setText
e.g.
secondViewController.titleHeaderText = [object name];
After that, in your secondViewController's viewDidLoad method, you can set the text of your label.
[self.titleHeader setText:self.titleHeaderText ];
EDIT:
The behavior of pushViewController seems to have changed in iOS 7.
I have tried and replicated your issue.
If you do not want the above change, a workaround is by accessing the view of secondViewController, so that its views will be loaded before you call label setText.
e.g.
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil code:[object code]];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController view];
[secondViewController.titleHeader setText:[object name]];
[secondViewController.headerView setBackgroundColor:colorHeaderGallery];

Rotation Not working in iOS-6.0 and above versions

I have prepared one view controller file named "CncWindowController" and In XIB file, i take window object (instead of UIView) and connected it to view outlet. So when I access its view, i get window object.
I'm accessing like it in AppDelegate.m file :
self.windowController = [[CncWindowController alloc] initWithNibName:#"CncWindowController" bundle:nil];
self.window = (UIWindow*) self.windowController.view;
Here, view is actually referring to window. But Rotation is not working in iOS6.0 and shouldAutorotate method is also not called.
If i will use window object like below then it works fine :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
What is wrong with my approach ? Any help of ideas how i should work autorotation in iOS-6 too using above approach ?
Thanks!

Best implementation for transitionWithView in Navigation Controller when the user tap BACK

I have 2 UIViewControllers inside a NavigationController.
The first one, A, has just an UISearchBar on top of a tableView, as the tableHeader.
The second one, B, has a view in the upper part of the screen (let's call it a custom TableHeader) and a table below this view.
I wanted to simulate the modal transitionFlipFromRight when pushing from UIViewController A to UIViewControllerB and to simulate the modal transitionFlipFromLeft when popping from UIViewController B to UIViewController A when the user tap the navigationItem.backBarButtonItem.
No problem for the push side:
UIViewController *vcB = [UIViewController alloc] init];
[self.navigationController pushViewController: vcB animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromRight
animations:nil
completion:nil];
It works as expected.
I have problems implementing the pop, the switch back from UIViewController B to UIViewController A.
I added this code in the UIViewController B:
-(void) viewWillDisappear: (BOOL) animated
{
[super viewWilDisappear: NO]
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
}
I can see the flip but I am not satisfied with the result because for a fraction of a second after the switch from B to A I can still see the B custom tableHeader, moved from left border by 10 points.
Should I manage the transition from B to A in viewWillDisappear or I am totally wrong in doing this?
If I am wrong, What is the correct way to handle the pop animation?
Thanks
Nicola
Why dont you try this in your viewWillDisappear itself and check whether this works?
UIViewController *vcA = [UIViewController alloc] init];
[[self retain] autorelease];
[self.navigationController pushViewController: vcA animated: NO];
[UIView transitionWithView:self.navigationController.view
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:nil];
[self.navigationController popViewControllerAnimated:NO];
This is a tested code. So it works fine. This should help you.

How to set the starting orientation to landscape?

Hi I was checking the orientations changes of iOS6 and I made everything work fine except one thing. There is no way to start the app on landscape.
How can I do to start the app on landscape? I found this How to force a UIViewController to Portrait orientation in iOS 6 but that's not working, the app ALWAYS start in portrait and I needed to start it on landscape...
When I go to an other view and then go back to the "initial view" it is on landscape! But when the app starts it's on portrait...
Thank you!!
----------------------------- UPDATE -------------------------------
This is how I'm loading from the app delegate the main view:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myViewController = [[myViewController alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:myViewController] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
----------------------------- UPDATE 2------------------------------
I made it work, I changed the previous code for:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope this is useful for someone else!
Have you tried this?
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
or
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
This is working for me in both iOS 6 and iOS 5
I have another problem on trying to rotate the screen than I realize I was making the mistake of try to load the new screen with:
[self.navigationController presentModalViewController:controller animated:YES];
instead of:
[self.navigationController pushViewController:controller animated:YES];
the second one works but the first one wasn't doing what I expected.
This is how I made it work:
self.navController = [[UINavigationController alloc] init] ;
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
[navController presentViewController:myViewController animated:NO completion:NULL];
I hope it helps someone else!
I've been wrestling with this too - this is how I've fixed it:
In viewDidLoad:
CGRect frame = self.view.bounds;
if (frame.size.height > frame.size.width) {
//hack to force landscape
CGFloat holdHeight = frame.size.height;
frame.size.height = frame.size.width;
frame.size.width = holdHeight;
self.view.bounds = frame;
}
But I'd prefer a better way.

Resources