使用NSTableView动画与绑定 [英] Using NSTableView Animations with Bindings

查看:191
本文介绍了使用NSTableView动画与绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到NSArrayController的NSTableView。 NSArrayController的contentSet属性绑定到NSMutableSet。一切都很棒。

I have a NSTableView that is bound to a NSArrayController. The NSArrayController's contentSet property is bound to a NSMutableSet. Everything works great.

现在我想使用NSTableView中的动画去除行。我可以做到这一点[NSTableView removeRowsAtIndexes:withAnimation:]和行快速动画离开,但是我从tableview中删除的对象仍然挂在支持tableview的NSMutableSet中。显然,我需要删除它。如果我尝试通过NSArrayController的removeObject:方法删除它,该对象立即从tableview消失,这意味着动画不会发生或被中途切断。

Now I want to use the animations built in to NSTableView to remove rows. I can do this with [NSTableView removeRowsAtIndexes:withAnimation:] and the row quickly animates away, however the object I removed from the tableview is still hanging out in the NSMutableSet that is backing the tableview. Obviously I need to remove it. If I try to remove it through the NSArrayController's removeObject: method then the object disappears from the tableview immediately which means the animation doesn't occur or gets cut off halfway through.

绑定工作奇迹,使事情变得更容易,但是当绑定和NSTableView动画被使用时,正确的方法是保持数据源和tableview同步?

Bindings work wonders and make things so much easier but what exactly is the proper method for keeping the data source and tableview in sync when both bindings and NSTableView animations are being used? The answer should also address how to add rows to a bound NSTableView using animations.

推荐答案

该模型需要在动画完成:

The model needs to be updated right after the animation is complete:

@IBAction func onRemoveClick(sender: AnyObject?) {
    let selection = listController.selectionIndexes
    NSAnimationContext.runAnimationGroup({
        context in
        self.tableView.removeRowsAtIndexes(selection, withAnimation: .EffectFade | .SlideUp)
    }, completionHandler: {
        self.listController.removeObjectsAtArrangedObjectIndexes(selection)
    })
}

绑定。在OS X 10.9,10.10& 10.11。

Works in my app with bindings. Tested on OS X 10.9, 10.10 & 10.11.

这篇关于使用NSTableView动画与绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆