Xuni for IOS のドキュメント
フィルタ処理

FlexGrid は、ICollectionView インタフェースを使用したフィルタ処理をサポートします。フィルタ処理を有効にするには、FlexGrid コントロールでフィルタ処理するデータのオブジェクトを決定する関数を collectionView.filter プロパティに設定します。FlexGrid は、検索ボックスを使用してデータをフィルタ処理する柔軟性を提供します。

ユーザーはフィルタ検索ボックスを追加し、必要に応じて高さ、幅、色、テキスト、フィルタ処理パターンなどの属性を設定できます。この例は、グリッド内で検索する値を入力するための単純なグレーのテキストボックスを示します。たとえば、フィルタテキストボックスに 22 と入力すると、Collection View インタフェースはグリッドデータをフィルタ処理して、22 が含まれているすべての値を表示します。

Objective-C
コードのコピー
@implementation FullTextFilterController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITextField *filterField = [[UITextField alloc] init];
    filterField.delegate = self;
    filterField.text = @"Enter text to Filter";
    filterField.returnKeyType = UIReturnKeyDone;
    filterField.keyboardType = UIKeyboardTypeDefault;
    filterField.backgroundColor = [UIColor lightGrayColor];

    FlexGrid *flex = [[FlexGrid alloc] init];
    flex.isReadOnly = true;
    flex.itemsSource = [CustomerData getCustomerData:100];
    flex.tag = 1;
    filterField.tag = 2;
    [self.view addSubview:flex];
    [self.view addSubview:filterField];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    FlexGrid *flex = (FlexGrid*)[self.view viewWithTag:1];
    UITextField *filterField = (UITextField*)[self.view viewWithTag:2];

    filterField.frame = CGRectMake(0, 65, self.view.bounds.size.width, 50);
    flex.frame = CGRectMake(0, 115, self.view.bounds.size.width, self.view.bounds.size.height-115);
    [flex setNeedsDisplay];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return true;
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    [textField selectAll:nil];
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    return true;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    FlexGrid *flex =  (FlexGrid *)[self.view viewWithTag:1];
    //NSMutableArray *array = [[NSMutableArray alloc] init];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"M/d/yy"];
    flex.collectionView.filter = ^ BOOL (NSObject *item){
        CustomerData *d = (CustomerData*)item;

        if ([[NSString stringWithFormat:@"%@", d.customerID] isEqualToString:textField.text]) {
            return true;
        }
        else if ([[NSString stringWithFormat:@"%@", d.countryID] isEqualToString:textField.text]) {
            return true;
        }
        else if ([[NSString stringWithFormat:@"%@", d.weight] isEqualToString:textField.text]) {
            return true;
        }
        else if ([d.first isEqualToString:textField.text]) {
            return true;
        }
        else if ([d.last isEqualToString:textField.text])
        {
            return true;
        }
        else if ([d.father isEqualToString:textField.text]){
            return true;
        }
        else if ([d.brother isEqualToString:textField.text]){
            return true;
        }
        else if ([d.cousin isEqualToString:textField.text]){
            return true;
        }
        else if ([[dateFormat stringFromDate:d.hireDate] isEqualToString:textField.text]) {
            return true;
        }
        else {
            return false;
        }
    };
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return true;
}

@end

 

 


Copyright © GrapeCity inc. All rights reserved.