[TUTORIAL] Navbar button linking!

Discussion in 'Jiggy Runtime Development' started by hockeypanda32, Apr 22, 2008.

  1. hockeypanda32

    hockeypanda32 Well-Known Member

    Joined:
    Dec 18, 2007
    Messages:
    2,183
    Likes Received:
    89
    Device:
    iPhone 4 (Black)
    Navbar Button Linking


    After using Commander's tut you now know how to make the simplest of app! Well I am going to show you how to link a navbar to something else with one simple code. First make your navbar.

    Code:
    var bar = new UINavigationBar( [ 0 , 0 , window.bounds[ 2 ] , 48 ] );
    bar.showButtonsWithLeftTitle( "[B]Info[/B]" , "[B]Info[/B]" , false );
    
    mainView.addSubview( bar );
    
    var itemOne = new UINavigationItem( "[B]NavBar[/B]" );
    bar.pushNavigationItem( itemOne );
    Set the Bold Things to whatever you want them called! The info's are the buttons on the NavBar, the "NavBar" is the header text of the NavBar.

    Now lets get on to linking the buttons!
    Add this line of code first.
    Code:
    bar.onButtonClicked = 
    function( theBar , theButton )
    This tells the app that you want the buttons to do something with the buttons.

    This next line defines what the buttons do.

    0 = right
    1 = Left

    Code:
    {
    if ( theButton == 1 )
    {
    alert("Replace this alert strip with anything you want the button to do!");
    }
    if ( theButton == 0 )
    {
    alert("Replace this alert strip with anything you want the button to do!");
    }
    }
    
    There you are, you now can make your NavBar buttons work for your app!

    Here should be your full code if you followed Commander's tut and know how to do that stuff!

    Code:
    Plugins.load( "UIKit" );
    
    var window = new UIWindow( UIHardware.fullScreenApplicationContentRect );
    window.setHidden( false );
    window.orderFront();
    window.makeKey();
    window.backgroundColor = [ 1 , 1 , 1 , 1 ];
    
    var mainView = new UIView();
    window.setContentView( mainView );
    
    var bar = new UINavigationBar( [ 0 , 0 , window.bounds[ 2 ] , 48 ] );
    bar.showButtonsWithLeftTitle( "[B]Info[/B]" , "[B]Info[/B]" , false );
    
    mainView.addSubview( bar );
    
    var itemOne = new UINavigationItem( "[B]NavBar[/B]" );
    bar.pushNavigationItem( itemOne );
    
    bar.onButtonClicked = 
    function( theBar , theButton )
    
    {
    if ( theButton == 1 )
    {
    alert("Replace this alert strip with anything you want the button to do!");
    }
    if ( theButton == 0 )
    {
    alert("Replace this alert strip with anything you want the button to do!");
    }
    }
    
  2. SUPERBXD

    SUPERBXD Member

    Joined:
    Jan 16, 2008
    Messages:
    932
    Likes Received:
    14
    Device:
    iPhone 5 (Black)
    Wow, Hockey , this is the best tutorial yet for jiggy nav Bars ! Nice !
  3. micaheljcaboose

    micaheljcaboose Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,855
    Likes Received:
    82
    Thanks hockey, this will help many people with their Navbars.
  4. hockeypanda32

    hockeypanda32 Well-Known Member

    Joined:
    Dec 18, 2007
    Messages:
    2,183
    Likes Received:
    89
    Device:
    iPhone 4 (Black)
    thx for the comments guys, anyone use it yet?
  5. The Ax

    The Ax Banned

    Joined:
    Mar 11, 2008
    Messages:
    647
    Likes Received:
    22
    Nice this is good
  6. hockeypanda32

    hockeypanda32 Well-Known Member

    Joined:
    Dec 18, 2007
    Messages:
    2,183
    Likes Received:
    89
    Device:
    iPhone 4 (Black)
    Thx for the comments

    *sticky*
  7. micaheljcaboose

    micaheljcaboose Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,855
    Likes Received:
    82
    Its already stickied in our forums, lol.
  8. blackjak231

    blackjak231 Member

    Joined:
    Oct 1, 2007
    Messages:
    759
    Likes Received:
    6
    Device:
    iPhone 4 (White)
    Thank you so much!!!
  9. Ezra

    Ezra Well-Known Member

    Joined:
    Feb 23, 2008
    Messages:
    1,122
    Likes Received:
    41
    Device:
    iPhone
    WOW, This is one of the best posts here

    Please Register or Log in to view images



    Thanks Hockeypanda!
  10. hockeypanda32

    hockeypanda32 Well-Known Member

    Joined:
    Dec 18, 2007
    Messages:
    2,183
    Likes Received:
    89
    Device:
    iPhone 4 (Black)
    No problem, a lot of people had a hard time with this!

    Please Register or Log in to view images

    , also GoJohnnyBoi just made a nice tut, check it out!

Share This Page