0

私は検索バーを理解しようとしています.APIを持っています.APIを「どこに」送信すると、データが得られます. しかし、リターンキーをタップしても何も得られません。

私のコードがあります。

    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
    [securityPolicy setAllowInvalidCertificates:YES];


    NSString *urlPath = [NSString stringWithFormat:@"http://test.com/api/index.php"];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    NSDictionary *parameters = @{@"process":@"search_record",@"where": self.searchBar.text};
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    [manager setSecurityPolicy:securityPolicy];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    [manager POST:urlPath parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSError *error = nil;
        NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];

        self.customerCards = [NSMutableArray array];
        NSArray *customersArray = [dataDictionary objectForKey:@"customer_list"];
        NSLog(@"%@",customersArray);
        for (NSDictionary *customersDictionary in customersArray) {
            ApiClass *customer = [ApiClass customersWithTitle:[customersDictionary objectForKey:@"adi"]];
            customer.tel = [customersDictionary objectForKey:@"tel"];

            [self.customerCards addObject:customer];

        }
        [self.tableView reloadData];

        NSLog(@"GET: %@", string);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];


}

私は何をすべきか。

ありがとう

4

0 に答える 0