推送视图:在发生现有转换或演示时;导航堆栈不会更新

Posted

技术标签:

【中文标题】推送视图:在发生现有转换或演示时;导航堆栈不会更新【英文标题】:Push view: while an existing transition or presentation is occurring; the navigation stack will not be updated 【发布时间】:2014-08-05 05:29:00 【问题描述】:

我在尝试推送视图控制器时收到此错误。 我从表格单元格中附加了一个segue, pushViewController:animated:在现有过渡或演示发生时调用;导航堆栈不会更新。

class PlaylistsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate 
let ItemRecordName = "Playlists"
var playlists = NSMutableArray()
@IBOutlet var tableView: UITableView?
var cloudm = CloudManager()
var container: CKContainer?
var publicDatabase: CKDatabase?
var edgePan = UIScreenEdgePanGestureRecognizer()



override func viewDidLoad() 
    super.viewDidLoad()


    self.setUpMenu()
    container = CKContainer.defaultContainer()
    publicDatabase = container?.privateCloudDatabase

    self.tableView!.contentInset = UIEdgeInsetsMake(64, 0, 0, 0)


func setUpMenu() 

    self.slidingViewController().topViewAnchoredGesture = ECSlidingViewControllerAnchoredGesture.Panning |  ECSlidingViewControllerAnchoredGesture.Tapping

    //self.navigationController.view.addGestureRecognizer(self.slidingViewController().panGesture)
    edgePan = UIScreenEdgePanGestureRecognizer(target: self, action: "menuButtonTapped")
   edgePan.edges = UIRectEdge.Left
    edgePan.delegate = self
    self.navigationController.view.addGestureRecognizer(edgePan)


    self.navigationController.navigationBar.translucent = true

    let icon = FAKIonIcons.naviconIconWithSize(40)
    icon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
    let iconImage = icon.imageWithSize(CGSizeMake(40, 40))

    let plusicon = FAKIonIcons.ios7PlusEmptyIconWithSize(30)
    plusicon.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor())
    let plusiconImage = plusicon.imageWithSize(CGSizeMake(30, 30))

    let barButton = UIBarButtonItem(image: iconImage, style: UIBarButtonItemStyle.Plain, target: self, action: "menuButtonTapped")
    let barButton2 = UIBarButtonItem(image: plusiconImage, style: UIBarButtonItemStyle.Plain, target: self, action: "openNameForPlaylist")
    barButton2.tag = 1
    let negativeSpacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
    let negativeSpacer2 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
    negativeSpacer.width = -10
    negativeSpacer2.width = 0.0

    self.navigationItem.leftBarButtonItems = NSArray(objects: negativeSpacer, barButton)
    self.navigationItem.rightBarButtonItems = NSArray(objects: negativeSpacer2, barButton2)


override func viewDidAppear(animated: Bool)  
    self.getPlaylists()

func menuButtonTapped () 
    self.slidingViewController().anchorTopViewToRightAnimated(true)

func getPlaylists() 
    cloudm.fetchPlaylistNames("Playlists", completionHandler: (records: NSMutableArray) -> Void in
        if records.count > 0 
            println("got Playlists")
            self.playlists = records
            self.tableView?.reloadData()
            //self.noFoodLabelAlpa(0, withDuration: 0, withDelay: 0)


         else 
            println("dont got Playlists")
            //self.noFoodLabelAlpa(1, withDuration: 1, withDelay: 1.8)
        
        )


override func didReceiveMemoryWarning() 
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.

func openNameForPlaylist() 
     var alert = UIAlertView(title: "Playlist Name", message: "Please choose a name for your Playlist",  delegate: self, cancelButtonTitle: "Done")
    alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
    alert.show()

func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: NSInteger)
println(alertView.textFieldAtIndex(0).text)
    addPlaylist(alertView.textFieldAtIndex(0).text)

func addPlaylist(name: String) 
    if playlists.count == 10 
        var alert = UIAlertView(title: "Playlist is full", message: "You've reached the maximum number of songs in your playlist, to add more please remove some", delegate: self, cancelButtonTitle: "ok")
        alert.show()
     else 
        println("playlist count = \(self.playlists.count)")
        var newRecord: CKRecord = CKRecord(recordType: ItemRecordName)
        //var playlistName = "Playlist \(self.playlists.count + 1)"
        newRecord.setObject(name, forKey: "playlistName")
        self.cloudm.saveRecord(newRecord)

        self.playlists.insertObject(newRecord, atIndex: 0)
        //self.playlists.addObject(newRecord)
        self.playlists.sortUsingDescriptors([NSSortDescriptor(key: "playlistName", ascending: true)])
        var indexPath = NSIndexPath(forRow: 0, inSection: 0)
        self.tableView?.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)


    

func numberOfSectionsInTableView(tableView: UITableView!) -> Int 
    return 1;

func tableView(tableView: UITableView!, heightForHeaderInSection section: Int) -> Int 
    return 1

func tableView(tableView: UITableView!, viewForFooterInSection section: Int) -> UIView 
    var view = UIView(frame: CGRect.zeroRect)
    return view



func tableView(tableView: UITableView!, heightForFootInSection section: Int) -> Int 
    return 1


func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int 
    return playlists.count


func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  
    let CellIndentifier: NSString = "playlistCell"

    var cell : UITableViewCell  = tableView.dequeueReusableCellWithIdentifier(CellIndentifier) as UITableViewCell
    var selectedView = UIView(frame: CGRectMake(0,0,cell.contentView.frame.size.width, cell.contentView.frame.size.height))
    cell.selectedBackgroundView = selectedView


    cell.backgroundColor = UIColor.clearColor()


    var records: CKRecord = self.playlists[indexPath.row] as CKRecord
    var playlist:String = records.objectForKey("playlistName") as String
    println("Playlists are \(playlist)")

    cell.textLabel.text = playlist


    return cell

func tableView(tableView: UITableView?, canEditRowAtIndexPath indexPath: NSIndexPath?) -> Bool 
    // Return NO if you do not want the specified item to be editable.
    return true


func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) 
    if editingStyle == .Delete 
        // Delete the row from the data source
        self.cloudm.deleteRecord(self.playlists[indexPath.row] as CKRecord)
        self.playlists.removeObjectAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    


func tableView(tableView: UITableView!, didEndEditingRowAtIndexPath indexPath: NSIndexPath!) 
    if playlists.count > 0 
        //self.noFoodLabelAlpa(0, withDuration: 0, withDelay: 0)

     else 
        //self.noFoodLabelAlpa(1, withDuration: 1, withDelay: 0)
    

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!)  
    var indexPath = self.tableView!.indexPathForSelectedRow()
    var record: CKRecord = self.playlists[indexPath.row] as CKRecord
    let playlistOpen: PlaylistsOpenViewController = segue.destinationViewController as PlaylistsOpenViewController
    playlistOpen.parentRecordID = record.recordID.recordName
    playlistOpen.cloudm = self.cloudm


更新: 好的,所以我已经安装了 xcode beta 5,现在模拟器和我的手机都收到了这个错误,这个错误在这个版本之前是不存在的。有什么想法吗?

【问题讨论】:

什么是错误,你得到了什么 基本上,当我在单击表格单元时尝试使用 segue 推送视图控制器时,我收到此错误,我还收到一些奇怪的日志,内容为:17545849:_UIScreenEdgePanRecognizerEdgeSettings.edgeRegionSize =13.000000 这个错误不是在didSelect中,而是在func setUpMenu()中,尝试排序这个方法,它是如何工作的,可能对你有帮助。 也没有推送和弹出,它们已被弃用。请记住这一点:) 我使用的是 segue,而不是真正的 push,所以从技术上讲,我应该说“show” 【参考方案1】:

这似乎是您正在使用的ECSlidingView 中的一个错误。见他们的issue tracker。有一种解决方法对某些情况有帮助,但恐怕在这里对您没有帮助。我们现在所能做的就是等待补丁或 Apple 破解他们在 Beta 5 中破坏的内容。

我决定把所有与 ECSliding 相关的东西都扔到窗外,然后使用 SWRevealViewController 重新开始。这个开关出奇地无痛,我花了大约一个小时的时间来开发一个大约 20K LOC 的应用程序。这是我向遇到此问题的任何人推荐的方法。

现在有一个修复合并到主分支中。我也将它发布在这里以供参考,它由 SpruceGoose429 提供并由 Github 上的 fcy 附加:

ECSlidingViewController.m 中替换以下代码:

- (id<UIViewControllerTransitionCoordinator>)transitionCoordinator 
    return self;

有了这个块:

- (id<UIViewControllerTransitionCoordinator>)transitionCoordinator

    // Return self if a transition is in progress (we're the transition coordinator).
    // Otherwise, defer to super.
    return ((_transitionInProgress)? self: [super transitionCoordinator]);

正如我提到的,此修复程序在 ECSlidingViewController 的 2.0.3 版中。

【讨论】:

我的解决方案有点类似,我基本上都选择退出滑动菜单并变得更基本,但我会在另一个项目上尝试一下,看看效果如何。谢谢 我明白了。 ECSliding 似乎是固定的,我用跟踪器中的解决方案替换了我的解决方案。但是,我坚持认为 SWReveal 似乎是更好的选择。很高兴它为你解决了:)【参考方案2】:

我花了一个小时后得到了解决方案。问题是弹出堆栈中的视图控制器,同时在当前视图控制器中显示任何警报框。 在 iOS 8 及更高版本中,它们不支持这样。 因此,您必须使用 ok 或 OKcancel 显示警报。 然后在单击输入按钮后导航或弹出到任何视图控制器。 它确实有效。

【讨论】:

以上是关于推送视图:在发生现有转换或演示时;导航堆栈不会更新的主要内容,如果未能解决你的问题,请参考以下文章

如何从导航堆栈中推送/弹出uiviewcontroller时收到警报

无法在选择搜索结果时执行 unwind segue - 导航堆栈将不会更新

从导航堆栈推送/弹出uiviewcontroller时如何收到警报

ios导航堆栈中的两个转换/演示文稿

创建一个可以模态显示或推送到导航堆栈的 UIView

推送导航控制器堆栈后视图不显示