-1

CustomCell に UITextFiled があります。次に、これらのセルを ProductDelivery クラスの UITableView にロードしています。UITextField *txtQty CellForRowAtIndexPath メソッドに初期値を割り当てています。

私の問題は、ユーザーが UITextField に入力した値が、Above Cell UItextField よりも大きくなってはならないことを検証したいということです。

ユーザーが UITextField CustomCell Class DidEndEding method class に値を入力するとき しかし、私はこの値を UITableView Class に入れたい それが Product Delivery です。したがって、それを検証して、新しい値で UITableView をリロードできます。誰かがこの問題を解決するのを手伝ってくれませんか??

@interface ProductDeliveryCell : UITableViewCell<UITextFieldDelegate>
@property(nonatomic,retain)IBOutlet UITextField *txtQty;
@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProDeliveryCell";
    cell =(ProductDeliveryCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell==nil) 
{

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ProductDeliveryCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0]; 
    }
 cell.txtQty.text=del.Qty;
return cell;
}
4

2 に答える 2

2

最良の方法は、入力されたすべての値を特別な辞書に保存することです。価値を置く場所を作成する必要NSMutableDictionaryがあります。また、セル内のすべてUITextFieldのセルには、独自のタグがindexPath.row値に設定されている必要があります (tableView:cellForRowAtIndexPath:メッセージ内)。メッセージでは、次のtextField:didEndEditingようなコードで入力された値を保存する必要があります。

[valuesDictionary setValue:textField.text forKey:[NSString stringWithFormat:@"field%02d", textField.tag]];

そのため、いつでも入力した値を確認できます。編集されたテキストフィールドのタグを取得[NSString stringWithFormat:@"field%02d", tag-1]し、辞書からキーの値を選択するだけです。

于 2012-08-24T10:08:41.877 に答える
1

currentValue などの変数に入力すると、textField の値が保存されます。

この問題ではUITextFieldDelegatesを使用してください。入力された値が入力された値よりも大きいかどうかを確認してください

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if(currentValue > 0)//(!(currentValue == 0)) //intially it will be zero
    {
       if([textField.text intValue] > currentValue)
       {
             //message value greater
             textField.text = [textField.text substringToIndex:[textField.text length] - 1]; //remove last number entered
        }
     }
}

新しい値を保存

- (void)textFieldDidEndEditing:(UITextField *)textField
{
  currentValue = [textField.text intValue]; //save new Value
}
于 2012-08-24T10:12:03.167 に答える