Dynamic Alert View Text Body
Can you edit the contents of an UIAlertView once it has been shown? I would like 开发者_运维百科to be able to update the text in it without having to dismiss and show a new one every time.
Thanks in advance,
Jonathan
There is a UIAlertView delegate called didPresentAlertView:. It is fired once the UIAlertView is presented on the view. Inside there you can set any of its properties. Here is an example:
- (void)viewDidLoad {
[super viewDidLoad];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"my message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
}
- (void)didPresentAlertView:(UIAlertView *)alertView
{
[alertView setTitle:@"My new title"];
[alertView setMessage:@"My new message"];
}
Go through this . I guess the MBProgressHUD library's mode switching display will suit your requirements better than messing up with alert views. That particular mode/component in the library shows multiple messages sequentially and you also have the provision to set timers for each message in the sequence.
Declare your UIAlertView
in the .h
, initiate it once (maybe in the viewDidLoad
) . Show it only when it is first needed and than try changing its contents when you need to with:
[alertView setTitle:@"new title"];
[alertView setMessage:@"new message"];
精彩评论