Set the warning box to the style with a ciphertext input box, and set the input box keyboard as the numeric keypad, judge the contents of the ciphertext input box, and pop up the corresponding prompt.

Source: Internet
Author: User

Project requirements

Set the warning box to the style with a ciphertext input box, and set the input box keyboard as the numeric keypad, judge the contents of the ciphertext input box, and pop up the corresponding prompt.

Nonsense not to say, directly on the question and answer code

#import "TableViewController.h"

@interface Tableviewcontroller () <UIAlertViewDelegate>

@property (nonatomic, Strong) Nsmutablearray * DATASOURCE;

-(ibaction) Buy: (ID) sender;

@end

@implementation Tableviewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.title = @ "shopping list";

_datasource = [@[@{@ "name": @ "effective OBJECTIVE-C 2.0" @ "price": @ "¥55.20"},

@{@ "name": @ "iOS components and frames" @ "price": @ "¥71.80"},

@{@ "name": @ "ios Core Development Manual" @ "price": @ "¥98.20"},

@{@ "name": @ "iOS Development paradigm (Advanced article)", @ "price": @ "¥70.00"},

@{@ "name": @ "iOS Development advanced" @ "Price": @ "¥55.30"},

@{@ "name": @ "iOS Programming (4th Edition)" @ "Price": @ "¥81.20"},

@{@ "name": @ "Objective-c advanced programming iOS with OS X multithreading and memory Management" @ "price": @ "¥41.70"}] mutablecopy];

[Self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:@ "Showcell"];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

}

#pragma mark-table View data source

-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {

return 1;

}

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {

return _datasource.count;

}

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:@ "Showcell" Forindexpath:indexpath];

Cell.textLabel.text = _datasource[indexpath.row][@ "name"];

Cell.detailTextLabel.text = _datasource[indexpath.row][@ "Price"];

return cell;

}

-(ibaction) Buy: (ID) Sender {

Uialertview * Alert =

[[Uialertview alloc] initwithtitle:@ "Tips"

message:@ "Please enter your password"

Delegate:self

cancelbuttontitle:@ "OK"

Otherbuttontitles:nil, nil];

The

Start writing code, set warning box to style with one ciphertext input box

Alert

End_code

[Alert show];

No.2

Start writing code, set the input box keyboard as the numeric keypad.

Uitextfield * TextField =

End_code

}

-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex{

NSString * title = @ "Hint";

NSString * message;

NSString * Cancelbuttontitle = @ "OK";

No.3

Start writing code to determine if the contents of the Ciphertext input box are @ "123456" and pop up a warning box to prompt @ "Password input error" or "Buy success"

Uitextfield * TextField =;

End_code

Uialertview * Wrongalert =

[[Uialertview alloc] Initwithtitle:title

Message:message

Delegate:nil

Cancelbuttontitle:cancelbuttontitle

Otherbuttontitles:nil, nil];

[Wrongalert show];

}

@end

Answer:

Uialertview * Alert =

[[Uialertview alloc] initwithtitle:@ "Tips"

message:@ "Please enter your password"

Delegate:self

cancelbuttontitle:@ "OK"

Otherbuttontitles:nil, nil];

The

Start writing code, set warning box to style with one ciphertext input box

Alert.alertviewstyle = Uialertviewstylesecuretextinput;

End_code

[Alert show];

No.2

Start writing code, set the input box keyboard as the numeric keypad.

Uitextfield * TextField = [alert textfieldatindex:0];

Textfield.keyboardtype = Uikeyboardtypenumberpad;

End_code

}

-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex{

NSString * title = @ "Hint";

NSString * message;

NSString * Cancelbuttontitle = @ "OK";

No.3

Start writing code to determine if the contents of the Ciphertext input box are @ "123456" and pop up a warning box to prompt @ "Password input error" or "Buy success"

Uitextfield *textfield = [Alertview textfieldatindex:0];

if ([Textfield.text isequaltostring: @ "123456"]) {

message = @ "Purchase succeeded";

}else{

message = @ "Password input error";

}

End_code

Set the warning box to the style with a ciphertext input box, and set the input box keyboard as the numeric keypad, judge the contents of the ciphertext input box, and pop up the corresponding prompt.

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.