【发布时间】:2017-10-11 04:00:59
【问题描述】:
我一直在使用应该在组末尾插入新项目的 NSOutlineView。我的代码被调用/命中断点,但新项目不会出现在 NSOutlineView 中,直到我杀死并重新启动应用程序。不确定我错过了什么。
@objc func didReceaveNewFeeds(aNotification: Notification) {
guard let userinfo: [AnyHashable : Any] = aNotification.userInfo,
let newFeed: ManagedFeed = userinfo[Notification.Name.newFeedKey] as? ManagedFeed else {
return
}
let index: Int = sidebarDataSource?.allFeeds.count ?? 0
unowned let unownedSelf: MainViewController = self
DispatchQueue.main.async {
unownedSelf.sidebarDataSource?.allFeeds.append(newFeed)
unownedSelf.outlineview.insertItems(at: IndexSet([index]),
inParent: unownedSelf.sidebarDataSource?.allFeeds,
withAnimation: .slideRight)
}
}
【问题讨论】:
-
可能不相关,但你为什么要使用那个麻烦的
unowned self?尽管许多人断言 GCD 确实不会导致保留周期。 -
重新加载大纲视图。
-
@ElTomato 不,不要,
insertItems应该更新 UI。 -
谢谢,使用
reloadData确实会显示所有项目,但它也会关闭所有展开的行,这是我试图避免的。 -
insertItems没有重新加载我的大纲视图。不知道为什么。