iOS 11's Navigation Bar's RightBarButton greyed out when returning from a pushed ViewController - ios11

I set a LeftBarButton "Cancel" and a RightBarButton "OK" this way
_barButtonOK = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonOKAction)];
[_barButtonOK setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setRightBarButtonItems:#[_barButtonOK]];
_barButtonCancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(barButtonCancelAction)];
[_barButtonCancel setTintColor:BUTTON_TEXTCOLOR];
[self.navigationItem setLeftBarButtonItems:#[_barButtonCancel]];
and they look like this
But when I push a ViewController and then pop it back, the OK button looks like being disabled (actually it is still enabled) like this
It is fine with iOS 10 but just grays out with iOS 11 and I don't know why. Any advice will be appreciated.

The problem is gone after the upgrading of iOS/Xcode at some point of time. Definitely it was an iOS defect.

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];

UINavigationController pushes UIViewController and nothing happens

Here are the relevant lines of code:
...
if([top class] == [SitesViewController class]){
BackupsViewController *backup = [[BackupsViewController alloc] initWithStyle:UITableViewStyleGrouped andID:cg_id];
[websites pushViewController:backup animated:NO];
[websites pushViewController:details_controller animated:YES];
websites is a navigation controller, and it is not nil.
Now the first time I run it, it works fine. But if I sign out, and sign back in it doesn't work. In fact, nothing happens. It stays on the same page it is on. I have already checked to make sure nothing is nil. I also know that I am entering into this if statement and none others.
Here is the logout function:
AppDelegate * appDelegate = (GCAppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.tabBarController setSelectedIndex:0]
UINavigationController * topViewController = appDelegate.tabBarController.viewControllers[0];
[topViewController presentViewController:loginScreen animated:YES completion:nil];
[topViewController popToRootViewControllerAnimated:TRUE];
[self deteleKeysAndTokens: (NSString*)k_apiSecret withAccessToken: (NSString*)k_accessToken withAccessSecret:(NSString*) k_accessSecret withkAPIKey: (NSString*)k_apiKey];
In case it might help, the backupViewController is downloading a list of websites, and the detailsViewcontroller is getting information about the websites. In fact, after making the call:
[websites pushViewController:backup animated:NO];
[websites pushViewController:details_controller
animated:YES];
(This is from the first bit of code I posted.)
I check to see what the topViewController is:
UIViewController * topView = websites.topViewController;
The topViewController is the details_controller. So I know it is being pushed onto the stack. However, nothing is happening. I am on the same view I started on. I was thinking that maybe it was because I hadn't gotten all the data. But that doesn't explain (a) why it works the first time through and (b) why it just doesn't display a blank page.
It's hard to say what is wrong as from code it's not clear what is the hierarchy of views.
First make sure you are using the correct navigation controller:
UINavigationController * websites = viewController.navigationController;
[websites pushViewController:anotherViewController animated:NO];
Also I'm not sure why your logout function is so complicated. Where do you execute it?
Anyway, its not good to present view controller on navigation controller and then pop it to root. And also both of them are animated...
Please provide more code.

Scrolling UIImageView through Interface Builder

Can someone PLEASE help me out here. I've been scouring the internet for 2 days now looking for ways on how to do this. It seems like it should be simple enough, but it's not.
Just like many others, I'm following along the Stanford iOS 5 tutorials and got to Lecture 8: Controller Lifecycle & Image/Scroll/WebViews. I know in this example, he's using springs and struts, but I'd like to see it get done just as easily in iOS 6.
So, in iOS 5, we just set the contentSize of our UIScrollView = to the size of our UIImageView. However, in iOS 6, we're told NOT to set contentSize.
So, I start off with a new project, drag in the UIImageView, embed it into a UIScrollView. I make sure that Auto Layout is enabled. I create outlets in my view controller for both the scroll view and the image view, then I look to my constraints. This is where I get stuck.
With how great everyone says the new constraints are, I can't believe that something as simple as this can't be so straight forward. I've gone through all my constraints. I've made sure that they're all adequate, yet when I run my app, the scroll view doesn't pan the image.
Now, if I implement the following:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.scrollView removeConstraints:self.scrollView.constraints];
[self.imageView removeConstraints:self.imageView.constraints];
NSDictionary *viewsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:self.scrollView, #"sv", self.imageView, #"iv", nil];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[sv]|" options:0 metrics:nil views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[sv]|" options:0 metrics:nil views:viewsDictionary]];
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[iv]|" options:0 metrics:nil views:viewsDictionary]];
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[iv]|" options:0 metrics:nil views:viewsDictionary]];
}
It works fine, but look at the constraints I set up. It's not like they're complicated. So why can't this be done easily in IB (at least not from everything I've tried)?
If this CAN be done in IB, can someone please show me how?!?!

Why does the MPMoviePlayerController call MPMoviePlayerPlaybackDidFinishNotification, when enter in fullsceen mode

I want to display a MPMoviePlayerViewController in full screen mode, but when the fullscreen button of the movieplayercontroller view is beeing pressed, first the MPMoviePlayerWillEnterFullscreenNotification gets called, as expacted, but than the MPMoviePlayerPlaybackDidFinishNotification is also beeing sent. As a reason it says MPMovieFinishReasonPlaybackEnded and i don't know, what i'm doing wrong. (In addition, i use iOS 6.0 and XCode 4.5.1)
My expactations are, that only the MPMoviePlayerWillEnterFullscreenNotification is beeing called.
Short explanation to the code below:
The MovieplayerViewController's view is beeing displayed in a tiny subview in my content view. When tapping the fullscreen-button, it first gets displayed as fullscreen but than also calls the exit button and stops playing (no crashes, nothing else).
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];
CGRect rect = videoView.frame;
rect.origin = CGPointZero;
[playerViewController.view setFrame:rect];
[playerViewController.moviePlayer prepareToPlay];
//movie this is my contents subview, where i add the viewcontroller's view as a subbview
[self.videoView addSubview:playerViewController.view];
[self.videoView setHidden:NO];
playerViewController.moviePlayer.useApplicationAudioSession = NO;
[playerViewController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:playerViewController.moviePlayer];
//i store the movieplayer in a property, so i can use it for further operations
self.myPlayer = playerViewController;
[playerViewController release];
And thats it!
When the resize (or fullscreen) button is being pressed, the moviePlayerDidFinishNotification: method also is being called
- (void)moviePlayerDidFinishNotification:(NSNotification*) aNotification {
int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playin
//in debug mode, it stops right at the NSLog
NSLog(#"");
}
else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
.. }
Is there something i do wrong or is there probably a change since iOS 6.0?
Ok, seems to be that there are some problems in the MPMoviePlayerViewController. What helped is to simply us the MPMoviePlayerController only.
For future reference the reason that your player showed in a small window was because you were setting:
[playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];
CGRect rect = videoView.frame;
rect.origin = CGPointZero;
[playerViewController.view setFrame:rect];
[playerViewController.moviePlayer prepareToPlay];
//movie this is my contents subview, where i add the viewcontroller's view as a subbview
[self.videoView addSubview:playerViewController.view];
[self.videoView setHidden:NO];
When you use an MPMoviePlayerViewController it creates it's own view controller. These calls are not necessary and will only create bizarre behavior. That's why the MPMoviePlayerController worked properly because it's designed to work inside another view controller.

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