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
相关产品推荐
相关产品推荐

