I have a problem when trying to display the GKMatchmakerViewController on my game view.
Normally I create a multiplayer match programmatically by auto-matching 2 opponents, and that works fine.
But when I try to display the standard Game Center Matchmaking view, it dismisses my game view and pushes me back to the menu.
Menu View -> Game View.
I think the problem might be that my menu view acts as my main view and all other views are removed when the Game Center view is displayed (since only one view controller can be shown at the time).
am I setting up my view hierarchy wrong? How should it be done so my Game View wont be dismissed when displaying the Game Center view?
EDIT - updated with code that calls the GKMatchMakerViewController
GameviewController with method that is called when I want to display the Game Center match making controller
- (void)presentCustomVSBattle {
ourRandom = arc4random();
[self setGameState:kGameStateWaitingForMatch];
AppDelegate * delegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
[[GCHelper sharedInstance] findCustomMatchWithMinPlayers:2 maxPlayers:2 viewController:delegate.viewController delegate:self];
}
// This method is called in GCHelper.m
- (void)findCustomMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
if (pendingInvite != nil) {
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
else {
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
request.playersToInvite = pendingPlayersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
}
In your case, the dismissView Controller calls look unnecessary, try getting rid of them :)
Related
Ok so here is a picture of my basic setup
Now this may not be the best way to set it all up but I did what I could with the knowledge I had to get the effect I wanted. Now my problem is originates in view 1 but only happens if you do this: Start at the menu click view 2,3 or 4 to go to that view then go to view 1 using the tabbar button now at this screen you would click the get pictures button which has the code below in its viewcontroller to show the image picker. Now the problem comes is if you go back at this point it takes you to the tabbarview that you clicked from the menu whether that was 2,3,or 4. It goes back fine if you clicked view 1 from the menu
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.selectedPhotos = [NSMutableArray array];
__block AGViewController *blockSelf = self;
ipc = [[AGImagePickerController alloc] initWithDelegate:self];
ipc.didFailBlock = ^(NSError *error) {
NSLog(#"Fail. Error: %#", error);
if (error == nil) {
[blockSelf.selectedPhotos removeAllObjects];
NSLog(#"User has cancelled.");
[blockSelf dismissViewControllerAnimated:YES completion:nil];
} else {
// We need to wait for the view controller to appear first.
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[blockSelf dismissViewControllerAnimated:YES completion:nil];
});
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
};
ipc.didFinishBlock = ^(NSArray *info) {
[blockSelf.selectedPhotos setArray:info];
NSLog(#"Info: %#", info);
//add all selected photos to the claim
[blockSelf setClaimPhotos:info];
[blockSelf dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
};
}
- (void)openAction:(id)sender
{
// Show saved photos on top
ipc.shouldShowSavedPhotosOnTop = NO;
ipc.shouldChangeStatusBarStyle = YES;
ipc.selection = self.selectedPhotos;
ipc.maximumNumberOfPhotosToBeSelected = 5;
// Custom toolbar items
AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"+ Select All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
return YES;
}];
AGIPCToolbarItem *flexible = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] andSelectionBlock:nil];
AGIPCToolbarItem *deselectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"- Deselect All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
return NO;
}];
ipc.toolbarItemsForManagingTheSelection = #[selectAll, flexible, flexible, deselectAll];
[self presentViewController:ipc animated:YES completion:nil];
}
(the open action is what is tied to the button on the vc)
I really need help on this one as Ive been stuck on this issue all week and have been trying all types of dissmiss view controller ect ect.
The problem was due a custom class on the TabBarController that was causing an unexpecting behavior with SelectedIndex property.
I am trying to display a QLpreviewcontroller on a UIVIewcontroller.
-(void)showPreview{
if(!_previewController){
_previewController = [[QLPreviewController alloc] init];
_previewController.dataSource = self;
_previewController.delegate = self;
}
// There will always be one item here
_previewController.currentPreviewItemIndex = 0;
[_previewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:_previewController animated:YES completion:nil];
}
the previecontroller is displayed but the transition is not animated. it just appears without any animation.
Popover appears properly when I click on button.
When orientation changes then it disappears & leave a black topbar.
Below is the reference image.
Can anyone suggest, why it is happening?
My Code:
EBFirstViewController *firstViewController = [[EBFirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
navigationController.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController setPopoverContentSize:CGSizeMake(320.0f, 527.0f)];
[popoverController presentPopoverFromRect:settingsBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
For That following code help to solve your problem.
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
// a cheat, so that we can dismiss all our popovers, if they're open.
if (ObjPopover) {
// if we're actually showing the menu, and not the about box, close out any active menu dialogs too
if (menuPopoverVC && menuPopoverVC == ObjPopover.contentViewController)
[menuPopoverVC.popoverController dismissPopoverAnimated:YES];
[menuPopoverPC dismissPopoverAnimated:YES];
menuPopoverPC = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// the user (not us) has dismissed the popover, let's cleanup.
ObjPopover = nil;
}
I have a UIViewController called MainViewController (it is inside a navigationController). I have another UIViewController called OptionsViewController. Inside OptionsViewController I have a logout button and when clicked it calls a delegate in the MainViewController:
- (IBAction) logout:(id)sender
{
[self.delegate viewController:self loginSuccess:YES]; //calls this delegate
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSString * username = [standardDefaults stringForKey:#"kApplicationUserNameKey"];
NSError * error = nil;
[standardDefaults removeObjectForKey:#"kApplicationUserNameKey"];
[SFHFKeychainUtils deleteItemForUsername:username andServiceName:#"convore" error:&error];
[self dismissModalViewControllerAnimated:YES];
}
The delegate called at MainViewController is:
- (void) viewController:(OptionsViewController*)viewCon loginSuccess:(BOOL)loadFlag
{
if (loadFlag){
LoginViewController* lvc = [[LoginViewController alloc] init];
lvc.delegate = self;
[self.navigationController presentModalViewController:lvc animated:YES];
//this same code works in the viewDidLoad (it presents the LoginViewController, but not here)
[lvc release];
[self.groups removeAllObjects];
[self.table reloadData];
Topic * topic = [Topic object];
topic.tid = [NSNumber numberWithInt:-2];
self.detailViewController.topic = topic;
self.detailViewController.detailItem = topic.tid;
}
}
The issue is that when this delegate is called, it should present a LoginViewController (as can be seen from the code above), however it doesn't. I tried to put the presentModalViewController code in the delegate inside the viewDidLoad of MainViewController and it shows up, but when trying to show it in this delegate it doesn't. Why is this? And yes I checked the delegate is getting called (tried putting a NSLog inside the delegate)
UPDATE:
The OptionsViewController is shown as a modalViewController as well with the following code from MainViewController:
- (IBAction)showOptions:(id)sender
{
if ([self.detailViewController.message isFirstResponder])
[self.detailViewController setViewMovedUp:NO];
OptionsViewController * opt = [[OptionsViewController alloc] init];
opt.delegate = self;
opt.mgvc = self;
UINavigationController * uinc = [[UINavigationController alloc] initWithRootViewController:opt];
uinc.navigationBar.tintColor = [UIColor blackColor];
uinc.modalPresentationStyle = UIModalPresentationFormSheet;
uinc.title = #"";
uinc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:opt animated:YES];
float xCenter = 384;
float yCenter = 512;
if (self.splitViewController.interfaceOrientation == UIInterfaceOrientationPortrait || self.splitViewController.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
xCenter = 384;
yCenter = 512;
} else if (self.splitViewController.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.splitViewController.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
xCenter = 512;
yCenter = 384;
}
uinc.view.superview.frame = CGRectMake(0, 0 , 318, 209);//it's important to do this after presentModalViewController
uinc.view.superview.center = CGPointMake(xCenter, yCenter);
[opt release];
}
When I try to just show OptionsViewController itself (without the UINavigationController, everything works fine). Why is this?
Are you sure your view is inside a navigation controller? If not, change the line to:
[self presentModalViewController:lvc animated:YES];
I have a UIPopoverController that is presented from a button on my UIViewController but when I tap on any part of the view that is not the popover it is not hiding?
The buttons that present this popover are created dynamically, you'll see that referenced in the code below:
-(IBAction)showModifiers:(id)sender{
[self.popoverController dismissPopoverAnimated:YES];
UIView *theSuperview = self.view;
CGPoint touchPointInSuperview = [sender locationInView:theSuperview];
UIView *touchedView = [theSuperview hitTest:touchPointInSuperview withEvent:nil];
currentPopoverTag = [touchedView tag];
NSLog(#"Show Modifiers %i %i", [touchedView tag], currentPopoverTag);
RepZioCoreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if (appDelegate.popoverController)
[appDelegate.popoverController dismissPopoverAnimated:YES];
self.modifierListPopoverViewController = nil;
ModifierListCollection *collection = [self.modifierLists objectAtIndex:[touchedView tag]-100];
ModifierList *modifierList = [self getModifierList:collection.ModifierListID];
self.modifierListPopoverViewController =
[[[ModifierListPopoverViewController alloc] initWithModifierList:modifierList withManufacturerID: self.manufacturerID] autorelease];
self.modifierListPopoverViewController.delegate = self;
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:modifierListPopoverViewController] autorelease];
[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
I realize it's unlikely, but does your ModifierListPopoverViewController class set its modalInPopover property to YES? (the default is NO, which should give you the behavior you're looking for).
It seems that some view tackles the touch event.