gpt4 book ai didi

iphone - 使用搜索栏时,表格仅显示 2 个标签(共 4 个)

转载 作者:行者123 更新时间:2023-11-29 13:03:59 26 4
gpt4 key购买 nike

我有一张带有 4 个标签的表格,效果很好。当我使用也能正常工作的搜索栏时,表格只显示两个标签:

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"airports" ofType:@"json"];

NSString *JSONData = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
NSArray *airports = [NSJSONSerialization JSONObjectWithData:[JSONData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];




finalArray = [[NSArray alloc]init];
finalArray = airports;
}



-(void)filterContentForSearchText:(NSString *)searchText{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF.airport_name contains[cd] %@", searchText];
self.searchResults = [finalArray filteredArrayUsingPredicate:resultPredicate];


}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{

[self filterContentForSearchText:searchString];
return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.tableView) {

return [finalArray count];
}else{

return [searchResults count];
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{static NSString *simpleTableIdentifier = @"AirportCell";

AirportCell *cell = (AirportCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AirportCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}

NSString *airportName = [[NSString alloc]init];
NSString *iataCode = [[NSString alloc]init];
NSString *icaoCode = [[NSString alloc]init];
NSString *countryAirport = [[NSString alloc]init];


if (tableView == self.tableView) {

airportName = [[finalArray objectAtIndex:indexPath.row] objectForKey:@"airport_name"];
iataCode = [[finalArray objectAtIndex:indexPath.row] objectForKey:@"iata_code"];
icaoCode = [[finalArray objectAtIndex:indexPath.row] objectForKey:@"icao_code"];
countryAirport = [[finalArray objectAtIndex:indexPath.row] objectForKey:@"country"];



cell.iataCodeLabel.text = iataCode;
cell.iataCodeLabel.font = [UIFont fontWithName:@"Verdana" size:13];
cell.icaoCodeLabel.text = icaoCode;
cell.icaoCodeLabel.font = [UIFont fontWithName:@"Verdana" size:13];

cell.airportNameLabel.text = airportName;
cell.airportNameLabel.font = [UIFont fontWithName:@"Verdana" size:13];

cell.countryLabel.text = countryAirport;
cell.countryLabel.font = [UIFont fontWithName:@"Verdana" size:13];

}else{



airportName = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"airport_name"];
iataCode = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"iata_code"];
icaoCode = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"icao_code"];
countryAirport = [[searchResults objectAtIndex:indexPath.row] objectForKey:@"country"];


cell.iataCodeLabel.text = iataCode;
cell.iataCodeLabel.font = [UIFont fontWithName:@"Verdana" size:13];
cell.icaoCodeLabel.text = icaoCode;
cell.icaoCodeLabel.font = [UIFont fontWithName:@"Verdana" size:13];

cell.airportNameLabel.text = airportName;
cell.airportNameLabel.font = [UIFont fontWithName:@"Verdana" size:13];

cell.countryLabel.text = countryAirport;
cell.countryLabel.font = [UIFont fontWithName:@"Verdana" size:13];
}


return cell;
}

enter image description here enter image description here

最佳答案

我相信您的 uisearchDisplayController 正在改变单元格的高度。答案位于on this question可能对你有帮助。

关于iphone - 使用搜索栏时,表格仅显示 2 个标签(共 4 个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19050812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com