程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了按下表格视图单元格后重定向到注释大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决按下表格视图单元格后重定向到注释?

开发过程中遇到按下表格视图单元格后重定向到注释的问题如何解决?下面主要结合日常开发的经验,给出你关于按下表格视图单元格后重定向到注释的解决方法建议,希望对你解决按下表格视图单元格后重定向到注释有所启发或帮助;

我在地图中加入了一个搜索栏,可以显示放置在地图上的特定图钉的不同结果。当他点击表格视图单元格时,我试图将用户重定向到特定的引脚。不幸的是,我收到此错误:

“线程 1:致命错误:在隐式解包可选值时意外发现 nil”

上线:

self.VC.liveMap.setRegion(region,animated: truE)

代码:

import UIKit
import MapKit

class SearchVIEwController: UIVIEwController,UItableVIEwDelegate,UItableVIEwDatasource,UISearchbarDelegate,CLLOCATIOnManagerDelegate {
    
    private var tableVIEw: UItableVIEw!
    var filteredOffices = [OfficeStats]()
    var filterednames = [String]()
    
    var VC = VIEwController()
    let searchbar = UISearchbar()
    
    
    overrIDe func vIEwDIDLoad() {
        super.vIEwDIDLoad()
        vIEw.BACkgroundcolor = .white
        sortList()
        setUpNavbar()
        searchbar.delegate = self
        filteredOffices = VC.officescopy
        
        VC.retrIEvenamecopy() { (success,filteredOffices) in
            if success {
                self.VC.sortList()
            } else {
                print("unsuceess")
            }
        }
        let barHeight = vIEw.window?.windowscene?.statusbaRMANager?.statusbarFrame.height ?? 0
        let displayWIDth: CGfloat = self.vIEw.frame.wIDth
        let displayHeight: CGfloat = self.vIEw.frame.height
        
        tableVIEw = UItableVIEw(frame: CGRect(x: 0,y: barHeight,wIDth: displayWIDth,height: displayHeight - barHeight))
        tableVIEw.register(UItableVIEwCell.self,forCellReusEIDentifIEr: "MyCell")
        tableVIEw.rowHeight = UItableVIEw.automaticDimension
        tableVIEw.datasource = self
        tableVIEw.delegate = self
        self.vIEw.addSubvIEw(tableVIEw)
        
    }
    
    func searchbarCancelbuttonClicked(_ searchbar: UISearchbar) {
        searchbar.text = ""
        searchbar.endEdiTing(true)
    }
    
    func searchbar(_ searchbar: UISearchbar,textDIDChange searchText: String) {
        filteredOffices = []

        if searchText == "" {
            filteredOffices = VC.officescopy
        }
        else{
            for offices in VC.officescopy {
                
                if offices.name.lowercased().contains(searchText.lowercased()){
                    filteredOffices.append(offices)
                }
            }
        }
        self.tableVIEw.reloadData()
    }
    
    func tableVIEw(_ tableVIEw: UItableVIEw,numberOfRowsInSection section: int) -> Int {
        print(filteredOffices.count)
        return filteredOffices.count
    }
    
    func tableVIEw(_ tableVIEw: UItableVIEw,dIDSELEctRowAt indexPath: IndexPath) {
        dismiss(animated: truE)
        print(filteredOffices[indexPath.count])
        let geoPoint = filteredOffices[indexPath.count].coordinates
        let LOCATIOn = CLLOCATIOnCoordinate2D(latitude: geoPoint.latitude,longitude: geoPoint.longitudE)
        let region = MKCoordinateRegion(center: LOCATIOn,span: MKCoordinateSpan(latitudeDelta: 0.005,longitudeDelta: 0.005))            
        self.VC.liveMap.setRegion(region,animated: truE)
    }
    
    overrIDe func vIEwDIDAppear(_ animated: Bool) {
        super.vIEwDIDAppear(animated)
        searchbar.becomeFirstResponder()
    }
    
    func tableVIEw(_ tableVIEw: UItableVIEw,cellForRowAt indexPath: IndexPath) -> UItableVIEwCell {
        let cell = UItableVIEwCell(style: UItableVIEwCell.CellStyle.subtitle,reusEIDentifIEr: "cell")
        cell.textLabel?.text = filteredOffices[indexPath.row].name
        cell.detailTextLabel?.text = filteredOffices[indexPath.row].LOCATIOn
        return cell
    }
    
    
    func setUpNavbar() {
        searchbar.sizetoFit()
        searchbar.searchbarStyle = .prominent
        searchbar.placeholder = "Kërko"
        searchbar.Tintcolor = UIcolor.lightGray
        searchbar.barTintcolor = UIcolor.lightGray
        navigationItem.titleVIEw = searchbar
        searchbar.isTranslucent = true
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的按下表格视图单元格后重定向到注释全部内容,希望文章能够帮你解决按下表格视图单元格后重定向到注释所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: