Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RutgerB

macrumors member
Original poster
Jul 13, 2008
32
1
Hi


I'm using the UIAlertView to ask the user whether he wants to start a new game. This is my code:

Code:
UIAlertView *replay = [[UIAlertView alloc] initWithTitle:@"Higher Lower" message:@"Play again?" 
                                         delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"yes",nil];
            
[replay show];
[replay release];

This shows the question to the user.
But how can I execute some code when the user pressed yes or no?

Thanks
Rutger
 

fishkorp

macrumors 68030
Apr 10, 2006
2,536
650
Ellicott City, MD
Since you're setting the delegate to "self" include this method:
Code:
#pragma mark UIAlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	// NO = 0, YES = 1
	if(buttonIndex == 0)
		// DO whatever "NO" is
	else {
		// Do whatever "YES" is
	}
}

Of course make the modifications to fit your needs
 

RutgerB

macrumors member
Original poster
Jul 13, 2008
32
1
Since you're setting the delegate to "self" include this method:
Code:
#pragma mark UIAlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
	// NO = 0, YES = 1
	if(buttonIndex == 0)
		// DO whatever "NO" is
	else {
		// Do whatever "YES" is
	}
}

Of course make the modifications to fit your needs

Thanks, this works :)

But I was wondering. When I have two messages and I want something different to happen when you pres yes of the first message and when you press yes of the second message.

So basically I need to hook the code you gave me to one specific message bubble.
 

yayaba

macrumors 6502
Apr 24, 2007
297
0
San Francisco Bay Area
Word of general advice: when you use any new class look in the documentation to see if there are delegate methods for them and skim through them to see if you'll need to use any of them. I found most classes need the delegate functions to actually make the class useful.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.