IOS-Get input text for Uitextfield

Source: Internet
Author: User

When the Uitextfield text changes, the data is updated according to the content, by writing the listener event.
To add a listener:

addTarget:self               action:@selector(textFieldDidChange:)     forControlEvents:UIControlEventEditingChanged// 监听事件

Listener events:

// 监听改变按钮- (void) textFieldDidChange:(UITextField*) sender {    // 文本内容    NSInteger times = [sender.text integerValue];    [_serviceNumList replaceObjectAtIndex:_servicePos withObject:[NSNumber numberWithInteger:times]];    // 总价    _totalPrice = (float)([_goodsList[_servicePos][@"Price"] floatValue]/100.0)*[[_serviceNumList objectAtIndex:_servicePos] integerValue];    [_totalPriceLabel setText:[NSString stringWithFormat:@"%0.1f", _totalPrice]];}

Remaining Uitextfield Properties:

        //Input BoxUitextfield *timesfield = [[Uitextfield alloc] Initwithframe:cgrectmake ( $*kviewratio,Ten*kviewratio, +*kviewratio, -*kviewratio)];//Position size[Timesfield Setborderstyle:uitextborderstyleroundedrect];//Outer box typensattributedstring* timestext =[[nsattributedstring Alloc] initwithstring:[NSStringstringwithformat:@"%ld", (Long) [[_servicenumlist Objectatindex:row] integervalue]];//Set text[Timesfield Setattributedtext:timestext]; [Timesfield setfont:[UifontSystemfontofsize: A*kviewratio]];//Text size[Timesfield Settextalignment:nstextalignmentcenter];//Text location[Timesfield setdelegate: Self];//Limit length[Timesfield AddTarget: SelfAction@selector(Textfielddidchange:) forcontrolevents:uicontroleventeditingchanged];//Monitoring Events[Itemview Addsubview:timesfield];//Add parent View

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS-Get input text for Uitextfield

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.