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