Uialertview alert-iOS development

Source: Internet
Author: User

Uialertview * myalert = [[uialertview alloc] initwithtitle: @ "sorry" message: @ "1234567890" delegate: Self cancelbuttontitle: @ "OK" identifier: nil, nil]; myalert. delegate = self; [myalert show]; // [myalert release]; // If release is not in the delegate below, remember to release it here; otherwise, the memory will leak.

Here is how to set delegate. To add delegate, we only need to display a pop-up window warning. We can use the following code to solve the problem without taking other actions:

[[[[UIAlertView alloc]                initWithTitle:@"sorry"                 message:@"1234567890"                 delegate:self                 cancelButtonTitle:@"OK"                 otherButtonTitles:nil, nil]                autorelease]                show];

What is the role of setting delegation? We can implement a delegate method of uialertview, so that we can process the action after the button is pressed in this method, and decide the shot-like operation based on the button that the user presses, for example, the operations to be performed after the OK button and the cancel button are pressed may be different:

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"Button %d pressed",buttonIndex);    [alertView release];}

See no? We can use buttonindex to determine which button the user presses and perform corresponding processing. At the same time, we can also click release here, because we may not know where to release the button in the above Code, so is release the most secure after you press the button?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.