- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Apple 将 NSPathControl 更改为与 Yosemite 中的 NSPathControlItem 一起使用。
但从我的角度来看,这些新类(class)根本不起作用。我试图在我的数据结构中显示自定义路径,但我在使用常规文件路径时遇到了类似的问题。是我还是苹果?
这是我的代码:
第一个片段的工作原理与此相同,它将显示一条路径。但这就是所有有效的方法。
//MARK: notifications
func selectionDidChange(notification : NSNotification)
{
if let item = notification.object as? Group
{
//get "path" components
var components : [String] = [item.title ?? "a"]
var ancestor : Group? = item.parent
while (ancestor != nil)
{
components.append(ancestor?.title ?? "b")
ancestor = ancestor?.parent
}
components.append("")
//convert to url
let path = ("MyScheme:/" + "/".join(components.reverse()))
pathControl?.URL = NSURL(string: path.stringByAddingPe
}
}
单击路径的任何部分以尝试从 NSPathControlItem 中获取任何属性根本不起作用。一切都返回零。
@IBAction func select(sender : AnyObject)
{
println(sender.clickedPathItem??.title)
println(sender.clickedPathItem??.URL)
}
如果我尝试使用 NSPathControlItem 构建路径,我无法设置任何属性(标题、url)。
pathComponent.URL = NSURL(string: path.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!)
//let url : NSURL? = NSURL(string: "/")
//let path = NSURL(fileURLWithPath: "/")
//pathComponent.URL = path as NSURL
pathComponent.attributedTitle = NSAttributedString(string: "/atttributes")
self.pathControl?.pathItems = [pathComponent]
println(pathComponent.description)
NSPathControlItem 也不应该被子类化。
这是怎么回事?
编辑
据我所知,NSPathControlItem 存在问题。创建 NSPathControlItem 的辅助函数。
func pathItem(title: String, imageName: String) -> NSPathControlItem
{
let item = NSPathControlItem()
item.title = title
item.image = NSImage(named: imageName)
return item
}
创建 NSPathControlItem 并打印出它们的标题的测试函数。
var pathItems : [NSPathControlItem] = []
for title in ["a","b","c"]
{
pathItems.append(self.pathItem(title, imageName: NSImageNameFolder))
}
for item in pathItems
{
println(item.title)
}
预期的输出是三行,a、b、c。我得到零,b,零。
如果您直接在 NSPathControl 上设置 pathItems,它将起作用。
self.pathControl?.pathItems = [
self.pathItem("a", imageName: NSImageNameFolder),
self.pathItem("b", imageName: NSImageNameFolder),
self.pathItem("c", imageName: NSImageNameFolder)]
但是,如果您间接设置 pathItems,一切都会变糟。
self.pathControl?.pathItems = pathItems //array of NSPathControl (see above)
编辑2
我又看了一眼。我在 pathItem 函数中配置了一个 NSPathControlItem。这里我设置了标题。如果我设置 attributedTitle 没有区别。使用 lldb 检查项目显示正确的(属性)标题值。
但是当我将 NSPathControlItem 的数组分配给 NSPathControl 时,标题的值为“”并且 attributedTitle 未初始化。
最佳答案
NSPathControlItem
严重损坏。从 10.11.3 开始,它包含以下方法,由 Hopper 反编译:
int -[NSPathControlItem release](int arg0) {
[arg0->_secretCell autorelease];
objc_assign_ivar(0x0, arg0, *_OBJC_IVAR_$_NSPathControlItem._secretCell);
rax = [[arg0 super] release];
return rax;
}
这显然应该是一个标准的 dealloc
覆盖,它释放 ivar,将其归零,然后调用 super。但是,由于某些可能与非法药物有关的未知原因,它是一个 release
覆盖。这意味着一旦其中一个对象被释放,即使在一些无害的操作过程中,它也会自毁并变得无法使用。
我创建了一些代码来使用运行时来消除错误的 release
覆盖并替换为适当的 dealloc
覆盖。这几乎没有经过测试,使用风险自负:
extension NSPathControl {
class func fix() {
let itemClass = NSPathControlItem.self
let superclass: AnyClass = class_getSuperclass(itemClass)
let releaseSelector = Selector("release")
let releaseMethod = class_getInstanceMethod(itemClass, releaseSelector)
let superReleaseIMP = class_getMethodImplementation(superclass, releaseSelector)
if method_getImplementation(releaseMethod) != superReleaseIMP {
method_setImplementation(releaseMethod, superReleaseIMP)
let ivars = class_copyIvarList(itemClass, nil)
var offsets: [Int] = []
var cursor = ivars
while cursor.memory != nil {
let ivar = cursor.memory
if String.fromCString(ivar_getTypeEncoding(ivar))?.hasPrefix("@") == true {
offsets.append(ivar_getOffset(ivar))
}
cursor++
}
free(ivars)
let superDeallocIMP = class_getMethodImplementation(superclass, "dealloc")
let dealloc: @convention(block) UnsafeMutablePointer<Int8> -> Void = { obj in
for offset in offsets {
let ivarPtr = UnsafeMutablePointer<COpaquePointer>(obj + offset)
let unmanaged = Unmanaged<AnyObject>.fromOpaque(ivarPtr.memory)
unmanaged.release()
ivarPtr.memory = nil
}
typealias DeallocF = @convention(c) (UnsafeMutablePointer<Int8>, Selector) -> Void
let superDeallocF = unsafeBitCast(superDeallocIMP, DeallocF.self)
superDeallocF(obj, "dealloc")
}
let deallocIMP = imp_implementationWithBlock(unsafeBitCast(dealloc, AnyObject.self))
class_addMethod(itemClass, "dealloc", deallocIMP, "v@:")
}
}
}
关于cocoa - NSPathControl 和 NSPathControlItem 是满是错误还是我? (优胜美地),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28284277/
当NSPathControl 用于表示本地机器上的路径时就可以了! 当我尝试表示远程服务器的虚拟路径时,问题出现了;在这种情况下,我必须相应地更改图标。 图片代表我得到的,不是我喜欢的。 现在的问题是
我的项目是一个基于文档的应用程序。我想使用 NSPathControl 对象在启动时显示打开文档的路径。 我将在此处插入代码: - (void)windowControllerDidLoadNib:(
我正在尝试自定义 NSPathControl(自定义外观、项目菜单),但经过几个小时后,我无法实现我想要的。您知道表示路径的替代控件吗? 预先感谢您的帮助, 问候, 最佳答案 您可以将一些自定义按钮与
我正在使用 cocoa 开发一个应用程序,但我遇到了 NSPathControl 的问题。 我将控件的样式设置为 Popup,当我启动应用程序并单击路径控件时,它会显示一个弹出菜单,其中包含我设置的
我想制作一个自定义的NSPathControl。NSPathCell 具有方法 + pathComponentCellClass,您可以在其中返回组件单元格的自定义类。我有一个 NSPathCompo
我在使用 NSPathControl 和自动布局时遇到一些问题。 我希望路径控件随窗口调整大小。这意味着,如果我扩大窗口的宽度,NSPathControl 也应该扩大。这有效。 现在的问题是,如果我将
请看这张图片: 我知道如何更改文本颜色: NSPathComponentCell *cell = [_pathControl pathComponentCells].firstObject;
我正在寻找一种方法来将 NSPathControl 的路径设置为“~/Desktop”。 最佳答案 [_pathControlOutlet setURL: [NSURL URLWithString:
来自 Apple's sample code和阅读 the docs我看不出配置 NSPathControl 的行为类似于例如Xcode 编辑器窗口中的“跳转栏”: 即让它代表一条路径(或其他类型的层
我正在与 NSPathControl 搏斗。具体来说,我有一个对话框(由 NIB 生成),要求用户提供标题和路径。该路径应该是用户硬盘上的本地路径。因此,在 Xcode 4 中,我拖入了一个 NSPa
iOS (iPhone/iPad) 上是否有一个控件可以像 OSX 中的 NSPathControl 一样工作? (要在事件上动态地将节点添加到根,这可以返回,在事件上删除节点...) 最佳答案 据我
我有带有弹出样式的NSPathControl。当我尝试选择其他“预定义”位置时 - 没有发生任何变化。 示例: -------------choice...-------------Some macB
Apple 将 NSPathControl 更改为与 Yosemite 中的 NSPathControlItem 一起使用。 但从我的角度来看,这些新类(class)根本不起作用。我试图在我的数据结构
我需要使用 NSBrowser 中当前选定的路径更新 NSPathControl,但我无法找到一种方法,以便在 NSBrowser 中的路径发生更改时获取通知。执行此操作的理想方法是观察 NSBrow
主题说的是全部。 我在 IB 中创建了一个带有占位符消息的 NSPathControl。运行应用程序,出现占位符文本。 然后,我将控件的值绑定(bind)到 Controller 的 NSURL* 属
我是一名优秀的程序员,十分优秀!