AlertSheet textFieldAtIndex command run? Devs help

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

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    ok, so im making my commandX, jiggy app, into an objective-c app now that im learning it. I have an alert sheet fullly functional that look slike this:


    NSArray *buttons = [NSArray arrayWithObjects

    Please Register or Log in to view images

    "Execute", nil];
    UIAlertSheet *alertSheet = [[UIAlertSheet alloc] initWithTitle

    Please Register or Log in to view images

    "CommandX" buttons:buttons defaultButtonIndex:1 delegate:self context:self];
    [alertSheet addTextFieldWithValue

    Please Register or Log in to view images

    "" label: @"Enter A Command Here"];
    [alertSheet setBodyText

    Please Register or Log in to view images

    "Please enter a command to execute];
    [alertSheet popupAlertAnimated:YES];


    now, i want to set it up to execute the user input command on a button click so i tried many things like this:


    - (void)alertSheet

    Please Register or Log in to view images

    UIAlertSheet*)sheet buttonClicked

    Please Register or Log in to view images

    int)button
    {
    if ( button == 1 )
    runCommand:[sheet textFieldAtIndex: 0];

    [sheet dismiss];
    }

    and

    - (void)alertSheet

    Please Register or Log in to view images

    UIAlertSheet*)sheet buttonClicked

    Please Register or Log in to view images

    int)button
    {
    if ( button == 1 )
    system("[sheet textFieldAtIndex: 0]";

    [sheet dismiss];
    }


    any suggestions to get it to work?
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Initiate the sheet like so:
    Code:
    	UIAlertSheet *alert = [[[UIAlertSheet alloc] init] autorelease];
    	[alert setDimsBackground: YES];
    	[alert setDelegate: self];
    	[alert setTitle: @"My alert Sheet"];
    	[alert setBodyText: @"This is the text on my Alert Sheet"];
    	[alert addButtonWithTitle: @"A button"];
    	[alert addButtonWithTitle: @"Another button"];
    	//And so on...
    	[alert popupAlertAnimated: YES];
    	[self resetGameState];
    
    In your case, there is no need to set up an array of buttons, so keep things simple on yourself.

    Then add this function to your code:
    Code:
    - (void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button
    {
    	if (button == 1) {
    		//Run the code this button does here.		
    	}
    
    	[sheet dismissAnimated: YES];
    }
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    ok thanks but I don't know the command to execute whatever is written the re textfiel on the alertsheet. That's my problem

Share This Page