Ios 如果表行中的某个值被更新,如何切换到另一个视图控制器?

Ios 如果表行中的某个值被更新,如何切换到另一个视图控制器?,ios,swift,uitableview,Ios,Swift,Uitableview,我在一个视图控制器中有一个表视图,其中包含一个类型项数组,因此每当更新(不断更新)某个项的某些属性(如下图所示)时,我希望能够切换到另一个视图控制器。但是我不知道我应该使用哪个tableview委托方法来完成这个任务 我试着用didSelectRowAt方法来实现这一点,但我希望能够在不进行选择的情况下进行转换,就在某个项目的精度低于我希望能够转换的特定项目的某个值时 func tableView(_ tableView: UITableView, didSelectRowAt indexPat

我在一个视图控制器中有一个表视图,其中包含一个类型项数组,因此每当更新(不断更新)某个项的某些属性(如下图所示)时,我希望能够切换到另一个视图控制器。但是我不知道我应该使用哪个tableview委托方法来完成这个任务

我试着用didSelectRowAt方法来实现这一点,但我希望能够在不进行选择的情况下进行转换,就在某个项目的精度低于我希望能够转换的特定项目的某个值时

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

    let item = items[indexPath.row]
    let beac = item.beacon
    let acc = Double(beac!.accuracy)
    if acc < 3.00 {
        if let Level2 = self.storyboard!.instantiateViewController(withIdentifier: "ReportVC") as? UIViewController {
            self.present(Level2, animated: true, completion: nil)
        }
    }
}
func tableView(tableView:UITableView,didSelectRowAt indexPath:indexPath){
取消选择行(at:indexPath,动画:true)
let item=items[indexPath.row]
设beac=item.beacon
设acc=双精度(beac!。精度)
如果acc<3.00{
如果让Level2=self.storyboard!。将eviewcontroller(标识符为“ReportVC”)实例化为?UIViewController{
自我呈现(2级,动画:真,完成:零)
}
}
}
这管用


但是需要一个tableview委托方法或其他方法,我不需要实际选择一行,但它仍然执行上述操作。

didSet
属性观察者用于在刚设置或更改属性时执行一些代码

为数组
项添加属性观察者
didSet
,并检查准确性。如果任何信标的精度低于3.00,则可以显示另一个视图控制器

var items: [CLBeacon] = [] {
    didSet {
        if items.contains(where: { $0.accuracy < 3.00 }) {
            if let reportVC = self.storyboard?.instantiateViewController(withIdentifier: "ReportVC") {
                self.present(reportVC, animated: true, completion: nil)
            }
        }
    }
}
var项:[CLBeacon]=[]{
迪塞特{
if items.contains(其中:{$0.00<3.00}){
如果let reportVC=self.storyboard?.instanceeviewController(带标识符:“reportVC”){
self.present(reportVC,动画:true,完成:nil)
}
}
}
}
如果要将精度低于3.0的特定信标传递给新的视图控制器,请尝试以下操作

var items: [CLBeacon] = [] {
    didSet {
        if let beacon = items.first(where: { $0.accuracy < 3.00 }) {
            if let reportVC = self.storyboard?.instantiateViewController(withIdentifier: "ReportVC") {
                reportVC.selectedBeacon = beacon
                self.present(reportVC, animated: true, completion: nil)
            }
        }
    }
}
var项:[CLBeacon]=[]{
迪塞特{
如果let beacon=items.first(其中:{$0.00<3.00}){
如果let reportVC=self.storyboard?.instanceeviewController(带标识符:“reportVC”){
reportVC.selectedBeacon=信标
self.present(reportVC,动画:true,完成:nil)
}
}
}
}

您可以使用以下计时器调用函数:

var timer = NSTimer()

override func viewDidLoad() {
    scheduledTimerWithTimeInterval()
}

func scheduledTimerWithTimeInterval(){
    // Scheduling timer to Call the function "updateCounting" with the interval of 60 seconds
    timer = NSTimer.scheduledTimerWithTimeInterval(60, target: self, selector: Selector("updateCounting"), userInfo: nil, repeats: true)
}

func updateCounting(){
    for item in items {
    let beac = item.beacon
            let acc = Double(beac!.accuracy)
            if acc < 3.00 {
                if let Level2 = self.storyboard!.instantiateViewController(withIdentifier: "ReportVC") as? UIViewController {
                    self.present(Level2, animated: true, completion: nil)
                    break
                }
            }
    }
}
var timer=NSTimer()
重写func viewDidLoad(){
scheduledTimerWithTimeInterval()
}
func scheduledTimerWithTimeInterval(){
//调度计时器以调用函数“updateCounting”,间隔为60秒
timer=NSTimer.scheduledTimerWithTimeInterval(60,目标:self,选择器:选择器(“更新计数”),userInfo:nil,repeats:true)
}
func updateCounting(){
对于项目中的项目{
设beac=item.beacon
设acc=双精度(beac!。精度)
如果acc<3.00{
如果让Level2=self.storyboard!。将eviewcontroller(标识符为“ReportVC”)实例化为?UIViewController{
自我呈现(2级,动画:真,完成:零)
打破
}
}
}
}
在这里,更新计数将每分钟调用一次,在此函数中,如果精度较低,则将显示第二个控制器

计时器持续时间,您可以决定哪一个最适合您,如果您获得了一些事件或代表的准确性变化,那么您可以提出第二个视图控制器也有


希望这能有所帮助。

“每当更新一个项目的值时”您在哪里以及如何更新一个项目的值?请允许我纠正我自己,很抱歉模棱两可,项目信标的准确性会不断更新,因此当准确性低于3.00时,我希望能够切换到该特定项目的另一个视图控制器。您是否在方法中获得新的信标?当您指的是“另一个视图控制器”时,您的意思是要更改该行的单元格外观?或者您真的想在整个tableview上导航并推送一个新的UIViewController吗?是的,我正在使用添加的信标更新locationmanager。