Saturday, August 11, 2012

Activity Indicator General & Message Box (Action Sheet) General



Drag onto window and place as requried
Select and turn on ‘Hide When Stopped’ from it’s properties.
Declare in #ViewController.h
        IBOutlet UIActivityIndicatorView *activityIndicator;
In #ViewController.m
//If view could be unloaded
//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
{
        [super viewDidUnload];

        [activityIndicator release];
        activityIndicator = nil;
}

//********** DEALLOC **********
- (void)dealloc
{
        [activityIndicator release];

        [super dealloc];
}

To turn on and off


        [activityIndicator startAnimating];

        [activityIndicator stopAnimating];

Message Box (Action Sheet) General




Show a main window message box

Alert View will automatically adjust for landscape orientation
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The username and password entered are not valid"
                                                                                                                message:nil
                                                                                                           delegate:nil
                                                                                                cancelButtonTitle:@"OK"
                                                                                          otherButtonTitles:nil];
                [alert autorelease];
                [alert show];

Show A Message Box

ActionSheet doesn’t auto adjust for landscape orientation
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
                                                                                                                        delegate:nil
                                                                                                   cancelButtonTitle:@"OK"
                                                                                           destructiveButtonTitle:nil
                                                                                                        otherButtonTitles:nil];
        [actionSheet showInView:[[self view] window]];
        [actionSheet autorelease];

OK Cancel Message Box

In your method that want’s to show the action box
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
                                                                                                                         delegate:self
                                                                                                        cancelButtonTitle:@"Cancel"
                                                                                           destructiveButtonTitle:@"OK"
                                                                                                        otherButtonTitles:nil];
        [actionSheet showInView:self.view];
        [actionSheet autorelease];
Add the delegate to the classes @interface
@interface #ViewController_iPhone : UIViewController
                        <UIActionSheetDelegate>
{
Add the delegate method
//*******************************************
//*******************************************
//********** ACTION SHEET DELEGATE **********
//*******************************************
//*******************************************
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
        // the user clicked one of the OK/Cancel buttons
        if (buttonIndex == [actionSheet destructiveButtonIndex])
        {
                //----- CLICKED OK -----

        }
        else if (buttonIndex == [actionSheet cancelButtonIndex])
        {
                //----- CLICKED CANCEL -----

        }
}

Multiple Buttons

        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
                                                                                                                         delegate:self
                                                                                                        cancelButtonTitle:@"Cancel"
                                                                                           destructiveButtonTitle:nil
                                                                                                        otherButtonTitles:@"Test1",@"Test2",nil];
        [actionSheet showInView:self.view];
        [actionSheet autorelease];
In the actionSheet delegate the buttonIndex starts from 0 being the top most button. If there is a destructiveButtonTitle then this is 0 otherwise it is the first otherButtonTitle.

No comments:

Post a Comment