[How To] Create and use a UIAlertSheet

Discussion in 'Jiggy Runtime Development' started by gojohnnyboi, Apr 23, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Ok, so to first make the alertsheet in your code is the first thing, and is done by doing this:


    Code:
    var sheetname = new UIAlertSheet( "Title of alertSheet" , [ "Button1" , "Button2" ] , 0
    sheetname.setTitle("This can be used as an alternative to defining the title above!");
    sheetname.setBodyText("This is the text that will be on the alertsheet");
    sheetname.setAlertSheetStyle(0) // 0 is the default blue, 1 and 2 are darker(
    ]

    now that you've made the alertSheet, you must call it in a function. There are several ways to do this, and the way that works for ALL types of alertsheets is to popupalertanimate it.

    Code:
    sheetname.popupAlertAnimated( true );
    this pops it up in the center of the screen and displays the content that you made for the alertsheet.

    another choice, that i believe only works for styles 1 and 2 is to present it from a view, like installer does for the installation confirmation prompt.'

    Code:
    sheetname.presentSheetFromAboveView( mainView ); // replace mainView with your main view that is set to your windows content view
    
    or
    
    sheetname.presentSheetFromBehindView( mainView ); // this is the coolest one

    a really cool thing to do with an alertsheet is to make it editable, by that meaning adding a text field to it:


    Code:
    sheetname.addTextFieldWithValue( "" );
    you can use that text on a button click with some function, im not exactly sure of it, but its like:

    Code:
    sheetname.textFieldAtIndex(0).text;
    for exact code on that, check my CommandX application code, as it does the same thing


    Now, to handle the functions on buttons.

    Code:
    sheetname.onButtonClicked = function( button )
    {
    if ( button == 1 )
    {
    executeShellCommand( "launchctl stop com.apple.SpringBoard" );
    }
    if ( button == 2 )
    {
    sheetname.dismiss( true );
    }
    };
    

    what we did here was make a parameter for the button in our function, then assaigned functions for each button. in this case, the first button would respring and the second button would dismiss the sheet.


    To dismiss the sheet, you set the name of the sheet and then dismiss, in a bool.

    Code:
    sheetname.dismiss( true );

    Also, if you wish for an alertsheet, or any other function for that matter to be executed or displayed first off on the application launch, use the onLoad function like this!


    onLoad = function()
    {
    sheetname.popupAlertAnimated( true );
    }



    Full example alertsheet:

    Code:
    var about = new UIAlertSheet( "About" , [ "OK" , "Ebay" ] , 0);
    about.setAlertSheetStyle(0);
    about.setBodyText( "This application was developed by: Gojohnnyboi" );
    about.onButtonClicked = function( button )
    {
    if ( button == 1 )
    {
    about.dismiss( true );
    }
    if ( button == 2 )
    {
    openURL("http://www.ebay.com");
    }
    };
    about.popupAlertAnimated( true );
    
    
    
  2. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    Good tutorial, hey do you have any of our pastebin links/my main.js on your computer by any chance?
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    thanks. and no sorry.
  4. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    you may want to add the full alert sheet at the bottom though
  5. Ezra

    Ezra Well-Known Member

    Joined:
    Feb 23, 2008
    Messages:
    1,122
    Likes Received:
    41
    Device:
    iPhone
    Great work!

    Another awesome post!

    Keep it up, I'm still learning all these things in jiggy

    Please Register or Log in to view images

Share This Page