在警报中允许位置权限之后,TableViewController不显示

时间:2019-07-15 12:06:14

标签: ios swift uinavigationcontroller uitabbarcontroller core-location

我的情节提要流是:

LaunchScreen-> LoginViewController-> LocationPermissionViewController-> TabbarController-> NavigationController-> RestaurantsTableViewController-> DetailViewController

用户登录后,当用户单击权限警报中的Allow选项时,应在标签栏控制器和导航控制器中显示应用RestaurantsViewController。问题是用户单击了警报中的Allow选项,导航和选项卡为shown,但表视图为not show

在允许使用权限后,我试图制作标签栏rootViewController。但是正如我说的,导航和标签栏都可以,但是表格视图数据没有显示。

以下是有关我的问题的屏幕录像链接:
youtube.com/watch?v=05Jumd4Bm6Q&feature=youtu.be

此功能正在AppDelegate中加载表格视图数据。

private func loadBusinesses(with coordinate: CLLocationCoordinate2D) {
    service.request(.search(lat: coordinate.latitude, long: coordinate.longitude)) { [weak self]
        (result) in
        guard let strongSelf = self else { return }
        switch result {
        case .success(let response):
            let root = try? strongSelf.jsonDecoder.decode(Root.self, from: response.data)
            let viewModels = root?.businesses
                .compactMap(RestaurantListViewModel.init)
                .sorted(by: { $0.distance < $1.distance })
            if let nav = strongSelf.window.rootViewController as? UINavigationController,
                let restaurantListViewController = nav.topViewController as? RestaurantTableViewController {
                restaurantListViewController.viewModels = viewModels ?? []
                //When Allow option tapped in location permission alert
            } else {
            let tab = strongSelf.storyboard
                .instantiateViewController(withIdentifier: "TabbarController") as! UITabBarController
                let appDelegate = AppDelegate.shared
                appDelegate.window.rootViewController = tab
                let restaurantTableViewController = self!.storyboard.instantiateViewController(withIdentifier: "RestaurantTableViewController") as? RestaurantTableViewController
                tab.viewControllers = [restaurantTableViewController] as! [UIViewController]
            }
        case .failure(let error):
            print ("Error: \(error)")
        } 
    }
}

如果在else块中放置这些代码块,则tableView显示它是数据。

{
strongSelf.navigationController = nav
strongSelf.window.rootViewController?.present(nav, animated: true)   {
(nav.topViewController as? RestaurantTableViewController)?.delegate = self
                    (nav.topViewController as? RestaurantTableViewController)?.viewModels = viewModels ?? []                    }
}

我没有收到任何错误。预期结果是,点击允许的权限按钮后,用户必须看到RestaurantsTableViewController

0 个答案:

没有答案