You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 26下Google Places自动补选框空白圆圈问题求助

iOS 16适配后Google Place自动补选框左侧空白圆圈的解决方法

适配iOS 16后,Google Places自动补选列表项左侧会出现无交互的空白圆圈,仅在iOS 16及以上版本出现。以下是两种处理方案:

方案一:直接移除空白圆圈

方法1:通过UIAppearance全局设置

在App启动时(比如AppDelegate的application(_:didFinishLaunchingWithOptions:)或SwiftUI的App结构体初始化方法中)添加以下代码,强制修改GMSAutocompleteViewController内Cell的默认样式:

import GooglePlaces

// 针对GMSAutocompleteViewController内的UITableViewCell,设置accessoryType为none
UITableViewCell.appearance(whenContainedInInstancesOf: [GMSAutocompleteViewController.self]).accessoryType = .none

方法2:遍历视图修改TableViewCell样式

在makeUIViewController方法中,找到GMSAutocompleteViewController内部的UITableView,直接修改Cell配置:

func makeUIViewController(context: UIViewControllerRepresentableContext<PlacePicker>) -> GMSAutocompleteViewController {
    let autocompleteController = GMSAutocompleteViewController()
    autocompleteController.delegate = context.coordinator
    
    // ... 原有配置代码 ...
    
    // 处理iOS16的空白圆圈问题
    autocompleteController.view.layoutIfNeeded()
    if let tableView = autocompleteController.view.subviews.first(where: { $0 is UITableView }) as? UITableView {
        tableView.delegate = context.coordinator
    }
    
    return autocompleteController
}

然后在你的GooglePlacesCoordinator中扩展实现UITableViewDelegate方法:

extension GooglePlacesCoordinator: UITableViewDelegate {
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        // 移除左侧空白圆圈
        cell.accessoryType = .none
        cell.accessoryView = nil
    }
}

方案二:替换为自定义图标

如果需要将空白圆圈替换为自定义图片,可在上述willDisplay方法中修改:

extension GooglePlacesCoordinator: UITableViewDelegate {
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        // 移除原有空白圆圈
        cell.accessoryType = .none
        
        // 设置自定义图标
        let customIcon = UIImage(named: "your-custom-location-icon")
        let iconView = UIImageView(image: customIcon)
        iconView.frame = CGRect(x: 0, y: 0, width: 22, height: 22)
        iconView.contentMode = .scaleAspectFit
        cell.accessoryView = iconView
    }
}

额外建议

优先尝试升级Google Places SDK到最新版本,官方可能已经针对iOS16的适配问题发布了修复补丁。检查你的Podfile,更新GooglePlaces版本后执行pod update即可。

内容的提问来源于stack exchange,提问作者dhaval123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 15:53:11