Reputation: 767
In ios7, I can present popovercontroller without any problem on iPad, but in ios8 it doesn't work
. I have searched for solutions in Google and here, but none works. This is the code I change for ios8:
privateChat = [[PrivateChatViewController alloc] initWithNibName:@"PrivateChatViewController" bundle:nil];
privateChat.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:privateChat];
[popoverController setDelegate:self];
//work in ios7
//[popoverController setPopoverContentSize:CGSizeMake(privateChat.view.frame.size.width,privateChat.view.frame.size.height) animated:YES];
//[popoverController presentPopoverFromRect:self.frame inView:self.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
//Edit for ios8, but not work
privateChat.preferredContentSize = CGSizeMake([privateChat.view.superview superview].frame.size.width,[privateChat.view.superview superview].frame.size.height) ;
[popoverController setPopoverContentSize: privateChat.preferredContentSize animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[popoverController presentPopoverFromRect:self.frame inView:[self.view.superview] permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
});
It doesn't work in ios8 and there is no crash too. What should I change or add to make it work ?
Upvotes: 0
Views: 414
Reputation: 1272
Here is my code that works perfectly in my project(iPad ios8 objective-c), (i faced same issue and bellow code solved my issue.) you should try this,
self.popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popover.delegate=self;
CGRect popoverRect = [self.view convertRect:[_btnimgProfilePic frame] fromView:[_btnimgProfilePic superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 100) ;
popoverRect.origin.x = popoverRect.origin.x;
// this works properly in my project
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),
^{
[self.popover presentPopoverFromRect:popoverRect inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
});
i hope this will help you.
Upvotes: 1