About
Home > Tutorials Home > Ios > UIActionsheet Part-2 in iOS

UIActionsheet Part-2 in iOS

Published on October 17, 2019 8:27:11 PM

UIActionSheet Example

We are an online tutoring company that has laid its foundation in utilizing Multiple Intelligence methodology to understand specific needs and learning styles of a student.This is the ButtonPressed example. In this example we will see how to load another view after pressing button. So let see how it will worked. Another Buttonpress reference you can find out from here ButtonView in iPhone.So that we patch a particular student to a tutor having a compatible teaching style. We have devised a smart online tutoring system to give you measurable results.Schools, cramped with students, fail to give your child the edge, the motivation and the right teacher guidance to help him find the true potential. We at Eonlinetutors.com make sure that your child gets the perfect learning environment to outperform.




Step 1 : Open the XCode and create a new Single View Based Application template. Give the application name "UIActionSheet Example". Copy this Code to the ViewController.h

#import <UIKit/UIKit.h>

@interface AbhishekViewController : UIViewController<UIActionSheetDelegate>

- (IBAction)loadActionSheet:(id)sender;

@property (retain, nonatomic) IBOutlet UIButton *loadActionSheetSecond;

- (IBAction)ActionSheetSecond:(id)sender;

@end

Step 2 : Copy the Following Code into your ViewController.m File.

#import "AbhishekViewController.h"

@implementation AbhishekViewController

@synthesize loadActionSheetSecond;

- (IBAction)loadActionSheet:(id)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"Multiple Options" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Email",@"Post on FaceBook",nil, nil];
	[sheet showInView:self.view];
	sheet.tag = 10;
	[sheet release];
}

- (IBAction)ActionSheetSecond:(id)sender
{
   UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"Multiple Options" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Red Color" otherButtonTitles:@"Green Color",@"Blue Color",nil, nil];
	[sheet showInView:self.view];
    sheet.tag = 11;
	[sheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 10)
	{
        if (buttonIndex == 0) 
		{
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Button Pressed" message:@"Delete Button Clicked" delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
            [alertView show];
            [alertView release];
        }
        else if (buttonIndex == 1)
		{
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Button Pressed" message:@"Email Button Clicked" delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
            [alertView show];
            [alertView release];
        }
        else if(buttonIndex == 2)
        {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Button Pressed" message:@"Post On Facebook Button Clicked" delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
            [alertView show];
			[alertView release];
		}
        else
		{
			UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Button Pressed" message:@"Cancel Button Clicked" delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
			[alertView show];
			[alertView release];
		}
	}
	else if(actionSheet.tag == 11)
	{
        if (buttonIndex == 0) 
		{
            [self.view setBackgroundColor:[UIColor redColor]];
		}
        else if (buttonIndex == 1)
		{
			[self.view setBackgroundColor:[UIColor greenColor]];

		}
        else if(buttonIndex == 2)
		{
			[self.view setBackgroundColor:[UIColor blueColor]];
		}
		else
		{
			UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Button Pressed" message:@"Cancel Button Clicked" delegate:nil cancelButtonTitle:@"Okey" otherButtonTitles:nil, nil];
			[alertView show];
			[alertView release];
		}
	}
}

@end
ALL COMMENTS (2)
Abhishek Bedre 2017-03-28 17:25:15
I have implemented my own "jarvis"....thanks to this example.        
2019-01-03 13:22:19
It is working fine in desktop but not working in android mobile