views:

30

answers:

1

Hi There, I would like to know that how to change UIAlert's cancel button text during runtime.

+5  A: 
- (void)showAlertWithTitle:(NSString*)title message:(NSString*)message cancelButtonTitle:(NSString*)cancelTitle {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:cancelTitle otherButtonTitles:nil];
    [alertView show]
    [alertView release];
}
aegzorz
@aegzorz, thanks for your response, but I'm already initialized it with same constructor. Also it is possible to change message, title properties of UIAlerView if you assign it to local variable on your view or controller. The question is, is it possible to change cancel button title in any part of code ?
fyasar
Well you set the cancel button title in the constructor, and that is in code. You can create the alert anywhere and just call show on it and then release it.
aegzorz
You can not release it suddenly, if you are using delegate of it such as clickedButtonAtIndex:
fyasar
When you call show on an UIAlertView it is added to UIWindow and retained, so you can safely release it after calling show. What you need to make sure is that the delegate is not released before the alert is dismissed.
aegzorz