UIAlertView - My mistake? Questions?

Discussion in 'iOS Programming' started by peacetrain67, Jul 17, 2009.

  1. peacetrain67 macrumors member

    Joined:
    Dec 20, 2007
    #1
    I have posted the full code at the very bottom in case I am missing something elsewhere then what I put up here. Although this code opens the application fine, and when the button to initiate this code (the login action) is chosen the alert does appear, I have a few problems currently:
    A) Choosing the "I agree" (case 0) still allows the alert to appear whenever the action is initiated (I am attempting to use the NSUserDefaults to prevent the alert from appearing after the I Agree button has been selected once)
    B) All four buttons just dismiss the alert, opposed to [3 of the 4] calling the views (using modalviewcontroller:action) I am intending to use:
    C) I would like to arrange the buttons in a box (in each corner) opposed to 4 horizontal buttons, which I know is possibly. I just can't recall/find the code to do something this. I think the code these questions can be answered from is here, but I have posted the full action below in case there is somewhere additional I need to edit. Thanks in advance
    Code:
    - (void)termsalert:(UIAlertView *)termsalert clickedButtonAtIndex:(NSInteger)buttonIndex { 
    	
    	switch(buttonIndex) {
    		case 0: {
    			[[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"FirstAlert"];
    			[[NSUserDefaults standardUserDefaults] synchronize];
    }
    			break;
    			
    		case 1: {
    			SubmittingTermsViewController *submitterms = [[SubmittingTermsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:submitterms animated:YES];
    		}
    			break;
    		case 2: {
    			ConditionsViewController *commissionsterms = [[ConditionsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:commissionsterms animated:YES];
    		}
    			break;
    		case 3: {
    			SitewidePoliciesViewController *privacyterms = [[SitewidePoliciesViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:privacyterms animated:YES];
    		}
    		default:
    			break;
    	}
    Code:
    - (IBAction)login:(id)sender
    {
    	UIAlertView *termsconditions = [[UIAlertView alloc] 
    									initWithTitle:@"Terms & Conditions"
    									message: @"terms text"
    									delegate:self
    									cancelButtonTitle:@"I Agree"
    									otherButtonTitles:nil];
    	[termsconditions addButtonWithTitle:@"Submit Terms"];
    	[termsconditions addButtonWithTitle:@"Commission Terms"];
    	[termsconditions addButtonWithTitle:@"Privacy Terms"];
    	[termsconditions show];	
    	[termsconditions release];
    	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    }
    - (void)termsalert:(UIAlertView *)termsalert clickedButtonAtIndex:(NSInteger)buttonIndex { 
    	
    	switch(buttonIndex) {
    		case 0: {
    			[[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"FirstAlert"];
    			[[NSUserDefaults standardUserDefaults] synchronize];
    			break;
    }
    			
    		case 1: {
    			SubmittingTermsViewController *submitterms = [[SubmittingTermsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:submitterms animated:YES];
    		}
    			break;
    		case 2: {
    			ConditionsViewController *commissionsterms = [[ConditionsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:commissionsterms animated:YES];
    		}
    			break;
    		case 3: {
    			SitewidePoliciesViewController *privacyterms = [[SitewidePoliciesViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:privacyterms animated:YES];
    		}
    		default:
    			break;
    	}
    
    	// TODO: spawn a login thread
    	activityindicatorlogin.hidden = FALSE;
    	[activityindicatorlogin startAnimating];
    	
    	buttonlogin.enabled = FALSE;
    	buttoninfo.enabled = FALSE;
    	buttonterms.enabled = FALSE;
    	buttonnewuser.enabled = FALSE;
    	buttonfullsite.enabled = FALSE;
    	buttonemailus.enabled = FALSE;
    	fieldpasswordlogin.enabled = FALSE;
    	fieldusernamelogin.enabled = FALSE;
    }
     
  2. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #2
    The first thing I see is that you have the break right after case 0 in the 2nd page of code. Is that right?
     
  3. peacetrain67 thread starter macrumors member

    Joined:
    Dec 20, 2007
    #3
    aha not in my actual code. sorry i didnt copy alot if it (i just copied and pasted the first part and then used the same copy/paste to do it again and then just typed the rest quickly. haha good thing i took more time with my actualy coding.

    this is copied and pasted in case i made other mistakes:
    Code:
    - (void)termsalert:(UIAlertView *)termsalert clickedButtonAtIndex:(NSInteger)buttonIndex { 
    	
    	switch(buttonIndex) {
    		case 0: {
    			[[NSUserDefaults standardUserDefaults] setValue:@"0" forKey:@"FirstAlert"];
    			[[NSUserDefaults standardUserDefaults] synchronize];
    }
    			break;
    			
    		case 1: {
    			SubmittingTermsViewController *submitterms = [[SubmittingTermsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:submitterms animated:YES];
    		}
    			break;
    		case 2: {
    			ConditionsViewController *commissionsterms = [[ConditionsViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:commissionsterms animated:YES];
    		}
    			break;
    		case 3: {
    			SitewidePoliciesViewController *privacyterms = [[SitewidePoliciesViewController alloc] initWithNibName:nil bundle:nil];
    			[loginview presentModalViewController:privacyterms animated:YES];
    		}
    		default:
    			break;
    	}
     

Share This Page