我有一个自定义单元格,它由3个不同的textfield txtsq,txtPOB,txtRxunit和这个自定义单元格组成,我的表视图中包含Controller,在表视图中,tableView中的Controller类为cellForRowAtIndexPath:(NSIndexPath *)indexPath ,现在我想设置我的3个不同文本字段的3个不同范围限制,这是在自定义单元格中,但我无法在我的
中设置范围-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string{
NSString *resultStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (textField.tag ==SQ) {
if([self isNumeric:resultStr]){
if(resultStr.length <= 3){
if(resultStr.length >= 1){
NSString *firstLetter = [resultStr substringWithRange:NSMakeRange(0, 1)];
if(![firstLetter isEqualToString:@"0"]){
return YES;
}
}
else{
return YES;
}
}
}
}else
if([self isNumeric:resultStr]){
if(resultStr.length <= 5){
if(resultStr.length >= 1){
NSString *firstLetter = [resultStr substringWithRange:NSMakeRange(0, 1)];
if(![firstLetter isEqualToString:@"0"]){
return YES;
}
}
else{
return YES;
}
}
}
return NO;
}
我已定义cell.txtSQ.tag=SQ;
cell.txtPOB.tag =POB;
cell.txtRxUnit.tag=RXunit;
使用此代码后,我的表视图数据不是持久的。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.skuNameArray.count > 0) {
OrderCell *cell = nil;
cell = (OrderCell *)[tableView dequeueReusableCellWithIdentifier:@"OrderCell"];
if(cell == nil){
cell = (OrderCell *)[OrderCell cellFromNibNamed:@"OrderCell"];
}
// Set Tag
cell.tag = indexPath.row;
cell.txtSQ.tag = indexPath.row;
cell.txtPOB.tag = indexPath.row;
cell.txtRxUnit.tag = indexPath.row;
// cell.txtSQ.tag=SQ;
//set Delegate
cell.txtPOB.delegate = self;
cell.txtRxUnit.delegate = self;
cell.txtSQ.delegate = self;
//set Values
cell.lblSKU.text = self.skuNameArray[indexPath.row];
cell.txtSQ.text = self.sqArray[indexPath.row];
cell.txtPOB.text = self.pobArray[indexPath.row];
cell.txtRxUnit.text = self.rxUnitArray[indexPath.row];
if (self.index == PCP || self.index == CURRENT_DAY_REPORTING_DETAIL) {
cell.txtSQ.enabled = NO;
cell.txtRxUnit.enabled = NO;
cell.txtPOB.enabled = NO;
}
[cell.txtSQ addTarget:self action:@selector(sqChanged:) forControlEvents: UIControlEventEditingChanged];
[cell.txtPOB addTarget:self action:@selector(pobChanged:) forControlEvents: UIControlEventEditingChanged];
[cell.txtRxUnit addTarget:self action:@selector(rxUnitChanged:) forControlEvents: UIControlEventEditingChanged];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
答案 0 :(得分:0)
您的SQ可能是动态的。所以,让它静止。
或
您可能没有将委托设置为自己。这样做:
cell.txtSQ.delegate = self;
cell.txtPOB.delegate = self;
cell.txtRxUnit.delegate = self;
仔细设置标签:
// Set Tag
cell.txtSQ.tag = SQ;
cell.txtPOB.tag = POB;
cell.txtRxUnit.tag = RXunit;