Use Uialertcontroller to create a warning window in IOS learning Note nine (2015.04.02) IOS8

Source: Internet
Author: User

1. Create a warning window using Uialertcontroller in IOS8

#pragma mark-a warning window that can be used only in IOS8
-(void) Showokaycancelalert
{
NSString *title = nslocalizedstring (@ "Modify group name", nil);
NSString *message = nslocalizedstring (@ "Please enter a new group name", nil);
NSString *cancelbuttontitle = nslocalizedstring (@ "Cancel", nil);
NSString *otherbuttontitle = nslocalizedstring (@ "OK", nil);

Uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:title message:message Preferredstyle:uialertcontrollerstylealert];
[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield)
{
Textfield.backgroundcolor = [Uicolor Lighttextcolor]; TextField can be customized here, such as changing the background color
}];

Uialertaction *cancelaction = [Uialertaction actionwithtitle:cancelbuttontitle style:uialertactionstylecancel handler:^ (Uialertaction *action) {
NSLog (@ "%s------%d-----Click Cancel Button", __function__, __line__);
}];
[Alertcontroller addaction:cancelaction];

Uialertaction *otheraction = [uialertaction actionwithtitle:otherbuttontitle style:uialertactionstyledefault Handler : ^ (uialertaction *action) {
Uitextfield *textfield = alertcontroller.textfields[0]; Gets the new group name in the input box
if (TextField.text.length = = 0)
{
[[[Uialertview alloc] initwithtitle:@ "Prompt" message:@ "Your new group name is unreasonable" Delegate:nil cancelbuttontitle:@ "OK" Otherbuttontitles:nil, nil] show];
Return
}
NSLog (@ "%s------%d-----Click OK button-----textfield.text =%@", __function__, __line__, Textfield.text);
[[Singleclient Sharedinstanceclient] clientaltergroupinfor: (int) Self.curGroup.g_02_gid Gname:textField.text]; Send a request to the server to modify the group name
}];
[Alertcontroller addaction:otheraction];

[Self Presentviewcontroller:alertcontroller animated:yes completion:nil];
}

Use Uialertcontroller to create a warning window in IOS learning Note nine (2015.04.02) IOS8

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.