UIActionSheet Dynamic Button


UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Dynamic"
                                                        delegate:self
                                               cancelButtonTitle:nil
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:nil];

if(buttonX)
{
    [actionSheet addButtonWithTitle:@"Button X"];
}
if(buttonY)
{
    [actionSheet addButtonWithTitle:@"Button Y"];
}
if(buttonZ)
{
    [actionSheet addButtonWithTitle:@"Button Z"];
}

[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;