UIAlert View Help

Discussion in 'iOS Development' started by maxk96, Jun 1, 2010.

  1. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    Hi, i have made an alert view with 2 buttons one saying done and one saying donate. How do i link up the donate button to goto paypal.com? Here is my source code.

    Code:
    - (IBAction)aboutPressed:(id)sender;
    {
    	UIAlertView *startAlert = [[UIAlertView alloc] initWithTitle:@"Information" message:@"If you have any problems with this application feel free to email me at sdk4you@gmail.com and please donate." delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:@"Donate", nil];
    	[startAlert show];
    	[startAlert release];
    }
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Set a delegate, which implements -[alertView:clickedButtonAtIndex:] or other methods documented here. You will need to check which button was pressed based on the index argument.

    To open Safari to a certain URL, use UIApplication's -[openURL:] method.
  3. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    im using a window based application how would i set a delegate?
  4. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    [OBJC]- (IBAction)aboutPressed

    Please Register or Log in to view images

    id)sender;
    {
    UIAlertView *startAlert = [[UIAlertView alloc] initWithTitle

    Please Register or Log in to view images

    "Information" message

    Please Register or Log in to view images

    "If you have any problems with this application feel free to email me at sdk4you@gmail.com and please donate." delegate:self cancelButtonTitle

    Please Register or Log in to view images

    "Done" otherButtonTitles

    Please Register or Log in to view images

    "Donate", nil];
    [startAlert show];
    [startAlert release];
    }[/OBJC]

    Now Follow Axis posts.
  5. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    thanks but i have fixed it by using
    Code:
    - (IBAction)aboutPressed:(id)sender
    {
    	UIAlertView *startAlert = [[UIAlertView alloc] initWithTitle:@"Information" message:@"If you have any problems with this application feel free to email me at sdk4you@gmail.com and please donate." delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"Donate" , nil];
    	
    	[startAlert show];
    	[startAlert release];
    }
    
    - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    	if (buttonIndex == 1)
    	{
    		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=F3JSNLF8KG6G8"]];
    	}
    }
  6. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    You can use cancelButtonIndex when the users click the cancel button which is Done in this case.

    like

    [objc] if (buttonIndex == [actionSheet cancelButtonIndex]) { // Done }[/OBJC]
  7. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    @OP: You should be more consistent with the way you use your brackets.

    What are you talking about?...

    That's not needed in his code, if the index is the done button, it won't do anything...
  8. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    He have the done button as the cancel button which doing nothing when the users clicked on it. It wouldn't looks good without the fully functionally buttons in the alert views because the users expected it to work.
  9. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Pressing the cancel button—in this case the "Done" button—causes the alert view to be dismissed and execution resumes on the main thread. No special action by the programmer is needed for that to happen. I'm not sure I understand what you mean.
  10. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    i agree with axis, also all i wanted for the cancel button was done which overall exits the uialert.

Share This Page