gpt4 book ai didi

ios - 模态关闭时的 UISearchController 问题

转载 作者:行者123 更新时间:2023-12-01 22:29:45 25 4
gpt4 key购买 nike

单击导航栏按钮时,我以模态方式呈现 View 。这个 View 有一个 tableview View 。单击 tableview 行时, View 将被关闭。添加 UISearchController 时遇到问题。当我从搜索栏的结果中单击一个项目时,模态消失,但在它后面是相同的确切 View ,但 tableview 显示的是一个完全填充的 View 。一秒钟后,该 View 以模态方式消失,我又回到了导航 View 。我包含了一个 gif,以帮助直观地解释我的问题。这是代码片段。

example gif

在带有 UISearchBar 的 View Controller 中:

在方法 cellforRowAtIndexPath

    //Check to see if results for search bar
if ([self.searchController isActive] && ![self.searchController.searchBar.text isEqualToString:@""]) {
restaurantCellData = self.searchResults[indexPath.row];
} else {
restaurantCellData = self.restaurantLocations[indexPath.row];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
RestaurantLocationData *restaurantCellData = (RestaurantLocationData *)[self.restaurantLocations objectAtIndex:indexPath.row];
if (self.restaurantSelectedCallBack) {
self.restaurantSelectedCallBack(restaurantCellData);
}
[self.nearByTableView deselectRowAtIndexPath:indexPath animated:YES];
}

在呈现 View Controller 中,我有回调 block 来关闭呈现的 View
vc.restaurantSelectedCallBack = ^(RestaurantLocationData *restaurantValue) {

self.restaurantInfo = restaurantValue;
[[API sharedInstance] setRestaurantInfoCustom:restaurantValue];

[self dismissViewControllerAnimated:YES completion:nil];
};

vc.searchSelectedCallBack = ^(RestaurantLocationData *restaurantValue) {
self.restaurantInfo = restaurantValue;

[[API sharedInstance] setRestaurantInfoCustom:restaurantValue];

[self dismissViewControllerAnimated:NO completion:nil];
};

最佳答案

如果你有这个definesPresentationContext = true -> 删除或设置为

并确保在关闭 ViewController 之前添加此代码
if searchController.isActive == true {
// Set the search controller active to false to prevent crash
searchController.isActive = false
}

关于ios - 模态关闭时的 UISearchController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37404759/

25 4 0
文章推荐: ios - 如何限制不支持空投功能的iOS设备?
文章推荐: ios - React-Native 的 Native 端能否向 React 请求信息? (桥接/ native 模块)
文章推荐: java - 你可以使 id 动态 -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com