IOS-Get UITextField input text

Source: Internet
Author: User

IOS-Get UITextField input text

When the UITextField text changes, update the data based on the content by writing the listening event.
Add a listener:

[TimesField addTarget: self action: @ selector (textFieldDidChange :) forControlEvents: UIControlEventEditingChanged]; // listens to events

Listener event:

// Listener change button-(void) textFieldDidChange :( UITextField *) sender {// NSInteger times = [sender. text integerValue]; [_ serviceNumList replaceObjectAtIndex: _ servicePos withObject: [NSNumber numberWithInteger: times]; // total price _ totalPrice = (float) ([_ goodsList [_ servicePos] [@ Price] floatValue]/100.0) * [[_ serviceNumList objectAtIndex: _ servicePos] integerValue]; [_ totalPriceLabel setText: [NSString stringWithFormat: @ % 0.1f, _ totalPrice];}

Other UITextField attributes:

// Input box UITextField * timesField = [[UITextField alloc] initWithFrame: CGRectMake (200 * kViewRatio, 10 * kViewRatio, 32 * kViewRatio, 20 * kViewRatio)]; // location size [timesField setBorderStyle: External]; // The External Frame Type NSAttributedString * timesText = [[NSAttributedString alloc] initWithString: [NSString stringWithFormat: @ % ld, (long) [[_ serviceNumList objectAtIndex: row] integerValue]; // set the text [timesField setAttributedText: timesText]; [timesField setFont: [UIFont systemFontOfSize: 12 * kViewRatio]; // text size [timesField setTextAlignment: blank]; // Text Location [timesField setDelegate: self]; // length limit [timesField addTarget: self action: @ selector (textFieldDidChange :) forControlEvents: UIControlEventEditingChanged]; // listens to the event [itemView addSubview: timesField]; // adds the parent View

 

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.