UINavigationBar - Won't Recognize UIAlertSheet!

Discussion in 'iOS Development' started by gojohnnyboi, Apr 8, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Ok, so i have this code to animate my "About" UIAlertSheet in my application but when it goes to compile, it says "About" is undeclared!

    Heres my code maybe someone can help me. I have the alertsheet correct, it pops up fine if i set

    [about popupAlertAnimated:YES];

    so heres the code:

    - (void)navBar

    Please Register or Log in to view images

    UINavigationBar*)navbar buttonClicked

    Please Register or Log in to view images

    int)button
    {
    switch (button)
    {
    case 0: [about popupAlertAnimated:YES]; break;
    }
    }


    Any help is appreciated and rep offered!
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Without even seeing your code, I'll tell you what you did wrong. You're declaring the alert sheet in one function, but calling it in another.

    I'd suggest reading up on variables, pointers, and scope.
    1 person likes this.
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

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

    Darn, i can see what you're saying, however i cant think of how to do that other than to make the AlertSheet in the NavBar onclicked function, but that seems impossible because the UIView wouldn't be declared either, making it impossible to add it to the view...
  4. Yongobongo

    Yongobongo New Member

    Joined:
    Dec 28, 2007
    Messages:
    121
    Likes Received:
    1
    Device:
    iPhone 4 (Black)
    Declare your global variables in your header file, that way they can be called/declared in any function.
  5. Commander147

    Commander147 Member

    Joined:
    Oct 10, 2007
    Messages:
    78
    Likes Received:
    4
    Device:
    iPhone 4 (Black)
    you have to create tge alert sheet before you can use it. You have to also make sure to create it after you have a mainview
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

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


    could i please get an example?
  7. Yongobongo

    Yongobongo New Member

    Joined:
    Dec 28, 2007
    Messages:
    121
    Likes Received:
    1
    Device:
    iPhone 4 (Black)
    Just define your Alert Sheet in your header file (and whatever else you're defining there):
    Code:
    @interface alertApp : UIApplication 
    {
    	UIAlertSheet *alertSheet;
    	UINavigationBar *navBar;
    	NSArray *buttons;
    }
    
    @end
    Then do whatever in the navigation bar that you need to do:
    Code:
    - (void)navBar:(UINavigationBar*)navbar buttonClicked:(int)button 
    {
    	switch (button) 
    	{
    		case 0: buttons = [NSArray arrayWithObjects:@"OK", @"No way", nil];
    			alertSheet = [[UIAlertSheet alloc] initWithTitle:@"this is my alert thing" buttons:buttons defaultButtonIndex:1 delegate:self context:self];
    			[alertSheet setBodyText:@"Would you like to eat my cheezburga?"];
    			[alertSheet popupAlertAnimated:YES];
    			break;
    	}
    }
    Pretty straight forward, if there's anything wrong with that I'm sorry because I just wrote that up quickly.
  8. bob12345333

    bob12345333 New Member

    Joined:
    Mar 1, 2008
    Messages:
    155
    Likes Received:
    0
    ?

    i know this is a pointless response but i have no idea at all what the heck ur talking about i feel like such a noob...

    Please Register or Log in to view images

  9. curthard89

    curthard89 New Member

    Joined:
    Sep 15, 2007
    Messages:
    178
    Likes Received:
    1
    Device:
    iPhone 3GS (Black)
    im asuming you on about the code....its object-c, the language behind the iphone, and hes trying to rig up the nav bar so when you click a button or somthing on it, an alert sheet will display, which is one of those sliding black semitransparent sheets that pop up from the bottom in camera app and installer etc.
  10. gojohnnyboi

    gojohnnyboi Well-Known Member

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


    ok i dont get the compi8ler error anymore but nothing happens on a buttonclick....

Share This Page