【问题标题】:Unwanted UITableViewCellAccessory magically appears after segue (Swift)不需要的 UITableViewCellAccessory 在 segue (Swift) 之后神奇地出现
【发布时间】:2015-03-13 08:38:52
【问题描述】:

我有一个应用程序,可以显示哪些同事在办公室内,哪些不在办公室内(基于很棒的 iBeacon 资料)。但是,显示它们的 UITableView 没有按预期工作。

很难解释,所以我添加了一些图片。

下面是 tableView 的正常外观。

这些是带有 UIImage 和 UILabel 的自定义单元格。我还在右侧为每个单元格设置了一个动作,该动作开始到他/她的个人资料页面。

按下此按钮时,segue 启动,我可以恢复(导航控制器)到此 ViewController。这里一切正常。

在顶部,您还可以使用 UISearchBar 来搜索特定的人。这个额外的 tableView 可以按预期工作,并且找到的人也会获得一个与他/她的个人资料页面相关的操作。

但是,当我在这个 segue 之后返回 tableView 时(只有这个,普通 tableView 中的那个可以正常工作),突然在我的单元格中添加了不需要的附件图标。

什么给了?我做错什么了吗? action字段有如下代码

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    var pingAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Ping", handler:{action, indexpath in
        AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
        self.searchDisplayController?.setActive(false, animated: false)
        self.performSegueWithIdentifier("openMap", sender: indexPath)
    })
    pingAction.backgroundColor = UIColor(red: 232/255, green: 75/255, blue: 4/255, alpha: 1)

    return [pingAction]
}

没有这条线

self.searchDisplayController?.setActive(false, animated: false)

返回到这个屏幕后,ViewController 甚至会完全变黑。

我从来没有在我的代码和我的 cellForRowAtIndexPath 中给我的单元格提供任何附件视图,我什至写过

customCell.accessoryType = UITableViewCellAccessoryType.None

但没有运气。奇怪的是,当从普通的 tableView 和 searchResultsTableView 转到个人资料页面时,它使用几乎完全相同的 segue,但是最后一个这样做会带来麻烦。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    ... // Other segues
    else if segue.identifier == "openMap" {
        let dvc: MapViewController = segue.destinationViewController as MapViewController
        var person: Person

        if self.searchDisplayController!.active == true {
            tableView = self.searchDisplayController!.searchResultsTableView
            person = self.filteredPersons[sender!.row]
        } else {
            tableView = self.tblPersons as UITableView
            person = personsManager.getPersonsMixed()[sender!.section][sender!.row]
        }

        dvc.person = person
    }
    ... // Other segues

任何帮助都会很高兴,我已经被这个问题困扰了好几个小时了。对于包含大量图像和代码 sn-ps 的长问题,我很抱歉,但我不知道问题出在哪里,所以我尝试提供尽可能多的信息。

【问题讨论】:

    标签: ios uitableview swift uisearchbar segue


    【解决方案1】:

    我通过删除整个 UISearchDisplayController 并改为实现 UISearchController 解决了这个问题。

    事实证明 UISearchDisplayController 在最新的 Xcode beta 版本中显示为已弃用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 2015-03-18
      • 1970-01-01
      相关资源
      最近更新 更多