User touches UIButton too many times iPhone - 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.

Related

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

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.

didSelectAnnotationView for map is called only once in iphone sdk

I implemented a map view in my app.
I implemented a didselect annotation method.
In this method,i open a popover. It works fine. But when the popover is dismiss & try to click on annotation again, then method is not called more.
if i clicked other annotation except previously select annotation then method will called.
My code is follow:
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView {
ReadingDatabaseAppDelegate *appDelegate = (ReadingDatabaseAppDelegate *)[[UIApplication sharedApplication] delegate];
if([self isPad])
{
detailsView *popUp=[[detailsView alloc] initWithNibName:#"detailsView_ipad" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(400, 400)];
AnnotationImageView *myLocationImage = (AnnotationImageView *)aView;
popUp.locationID = myLocationImage.locationID;
NSLog(#"%d",popUp.locationID);
popUp.list=listdata;
detView.fromMapView = TRUE;
if (appDelegate.preferenceRow == 1) {
detView.title = #"ATM Details";
popUp.isBranch = 0;
}
else {
detView.title = #"Branch Details";
popUp.isBranch = 1;
}
CGPoint annotationPoint = [mapView convertCoordinate:aView.annotation.coordinate toPointToView:mapView];
float boxDY=annotationPoint.y;
float boxDX=annotationPoint.x;
CGRect box = CGRectMake(boxDX,boxDY,5,5);
UILabel *displayLabel = [[UILabel alloc] initWithFrame:box];
[popView presentPopoverFromRect:displayLabel.frame inView:mapView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[displayLabel release];
}
}
** How can i solve this??**
When you dismiss your popover, deselect the annotation using -deselectAnnotation:animated:.

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

presentModalView not shown when called inside delegate

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

UIPopoverController presented from a UIButton does not hide?

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.