iphone - different alert views in one viewcontroller:
The following code is used to display two different alerts with different backgrounds in the same screen, put the following code snippet into your .m file;
Step 1: Define the key tokens.
Step 2: Declare your alert views where ever needed like this. Don't forget to add tag.The following code is used to display two different alerts with different backgrounds in the same screen, put the following code snippet into your .m file;
Step 1: Define the key tokens.
#define AlertOne 1
#define AlertTwo 2
#define AlertTwo 2
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"AlertView Title" message:@"Message one" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK1", nil]; alert1.tag = AlertOne; // assigning the tag for this alert [alert1 show]; [alert1 release]; UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"AlertView Title" message:@"Message two" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK2", nil]; alert2.tag = AlertTwo; // assigning the tag for this alert [alert2 show]; [alert2 release];
- (void)willPresentAlertView:(UIAlertView *)alertView { UIImage *alertImage = [[UIImage alloc] init]; if(alertView.tag == AlertOne) { alertImage = [UIImage imageNamed:@"orange.png"]; } else if(alertView.tag == AlertTwo) { alertImage = [UIImage imageNamed:@"blue.png"]; } alertImage = [alertImage stretchableImageWithLeftCapWidth:16 topCapHeight:14]; CGSize theSize = [alertView frame].size; UIGraphicsBeginImageContext(theSize); [alertImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)]; alertImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [[alertView layer] setContents:[alertImage CGImage]]; }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == AlertOne) {
if(buttonIndex == 0) {
// your code here
}
}
else if(alertView.tag == AlertTwo) {
if(buttonIndex == 1) {
// your code here
}
else
NSLog(@"Hai codingcluster");
}
0 comments:
Post a Comment
Share your thoughts here...