View is dismissing to the wrong view with tabbar and navigation controller - iphone

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.

Related

Displaying Game Center GKMatchmakerViewController dismisses other view

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 :)

UIPopoverController disappears when ipad orientation changes

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

How use two subsequent MBProgressHUD messages

I wan to to show a message using the MBProgressHUD during the uploading via NSURL string. So i code that:
MBProgressHUD *hud1 = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud1.labelText = #"sending info ...";
hud1.minShowTime =10.0;
NSURL *url =[NSURL URLWithString:self.urlToUpload];
the 10 second time is in order to wait some time i want user wait. It works, but I would show another message when the first desappear. Using another:
MBProgressHUD *hud2 = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud2.labelText = #"SENT!";
hud2.minShowTime =2.0;
it is not useful, because this message overlaps the first one.
Any tips about that?
I would remove the first HUD in your -connectionDidFinishLoading method or wherever you get notification that the string has been uploaded successfully.
[MBProgressHUD hideHUDForView:self.view animated:YES];
Then you can add your next HUD for 1-2 seconds. By just adding it via a specific time, there is no way to accurately remove the first HUD before the next one shows.
This was taken from the MBProgressHUD demo project. I would use this to display your timed completion HUD.
HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
// The sample image is based on the work by http://www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
+(void)toast:(NSString*) str view:(UIView*)view delegate:(id)delegate type:(IconType)type{
[MBProgressHUD hideHUDForView:view animated:YES];
MBProgressHUD * HUD = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:HUD];
NSString* strImage;
switch (type) {
case kNone:
strImage=nil;
break;
case kOK:
strImage=#"37x-Checkmark.png";//NSString stringWithFormat:#"%#",
break;
case kError:
strImage=#"ic_cancel_white_24dp.png";//NSString stringWithFormat:#"%#",
break;
default:
break;
}
HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:strImage] ];
// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = delegate;
HUD.labelText = str;
HUD.userInteractionEnabled = NO;
[HUD show:YES];
[HUD hide:YES afterDelay:1.5f];
}

image picker popover

AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) {
if (error == nil)
{
NSLog(#"User has cancelled.");
[self dismissModalViewControllerAnimated:YES];
} else
{
NSLog(#"Error: %#", error);
// Wait for the view controller to show first and hide it after that
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){
[self dismissModalViewControllerAnimated:YES];
});
}
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
} andSuccessBlock:^(NSArray *info) {
NSLog(#"Info: %#", info);
[self dismissModalViewControllerAnimated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}];
popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view.window
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
was able to present it, but, even I change the size its still the same, and when I pressed the DONE button, it removes my View controller not the imagepicker. Help please. I present it in a popover cause I think that, thats's why its slow it because imagepicker should be present with popover for iPad.
Are you implementing the AGImagePickerController delegates?
- (void)agImagePickerController:(AGImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
There you can dismiss your UIPopoverController.
resize set it this way:
[popoverController setPopoverContentSize:CGSizeMake(1024, 500)];
then in your andSuccessBlock and other part you used:
[self dismissModalViewControllerAnimated:YES];
should be
[popoverController dismissPopoverAnimated:YES];
That's why ViewController is being dismissed or removed from the view, because it is being dismissed the wrong way.

User touches UIButton too many times iPhone

If the user gets impatient and touches this button before the next view can load, I get nested view issues, why isn't this working? I assumed that turning the button BOOL enabled to no would fix it, but it doesn't.
-(IBAction)start:(id)sender
{
startButton.enabled = NO;
[activity startAnimating];
[locationManager stopUpdatingLocation];
ViewController *view = [[ViewController alloc]init];
NSManagedObjectContext *context = [self managedObjectContext];
view.managedObjectContext = context;
[self.navigationController pushViewController:view animated:YES];
}
That OP code should work. Ensure startButton is the correct button and connected in IB.
If the action is caused by the button you want to disable then self.enabled = NO; is more direct.
Have the entire thing inside an if statement.
-(IBAction)start:(id)sender
{
if(variable == TRUE){
[activity startAnimating];
[locationManager stopUpdatingLocation];
ViewController *view = [[ViewController alloc]init];
NSManagedObjectContext *context = [self managedObjectContext];
view.managedObjectContext = context;
[self.navigationController pushViewController:view animated:YES];
}
}
And set your variable = to TRUE or FALSE whenever you need to.