gpt4 book ai didi

Swift OSX - 设置值时无法识别的选择器发送到 NSObject 子类上的实例

转载 作者:行者123 更新时间:2023-11-28 08:02:14 25 4
gpt4 key购买 nike

我正在尝试填充一个 NSObject 自定义类数组,但是当我插入数据时,我收到一个错误:[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0

调用类的 Action

@IBAction func selecionarFotosButtonClicked(_ sender: NSButton) {

let panel = NSOpenPanel()
panel.canChooseFiles = true
panel.canChooseDirectories = false
panel.allowsMultipleSelection = true
panel.canCreateDirectories = false
panel.allowedFileTypes = NSImage.imageTypes

panel.beginSheetModal(for: view.window!) { (result) in

if result.rawValue == NSFileHandlingPanelOKButton {
for url in panel.urls {
let fotoNSImage = NSImage(byReferencing: url)
let fotoNSImageRedim = Ferramentas.redimensionaNSImage(imagem: fotoNSImage, tamanho: NSSize(width: 200, height: 200))
let fotoNSImageRep = NSBitmapImageRep(data: (fotoNSImageRedim.tiffRepresentation)!)
let fotoNSImagePng = fotoNSImageRep?.representation(using: NSBitmapImageRep.FileType.png, properties: [:])

//let fotoProduto = FotoProduto(foto: PFFile(data: fotoNSImagePng!)!, categorias: [])
let fotoProduto = FotoProduto()
fotoProduto.foto = PFFile(data: fotoNSImagePng!)
fotoProduto.categorias = []
fotoProduto.imagemCapa = false

self.projeto?.fotos = [FotoProduto]()
self.projeto?.fotos.append(fotoProduto)
}

self.verificaCapaDefinida()

if !self.capaDefinida {
let indiceImagem = IndexPath(item: 0, section: 0)

self.definirImagemCapa(indice: indiceImagem, limparSelecao: true)
} else {
self.fotosProjetoCollectionView.deselectAll(self)
self.fotosProjetoCollectionView.reloadData()
}
}
}
}

FotoProduto 类

import Cocoa

import Parse

class FotoProduto: NSObject {

@NSManaged var foto: PFFile?
@NSManaged var categorias: [String]
@NSManaged var imagemCapa: Bool

override init() {
super.init()
}
}

这是完整的错误:

2017-09-21 07:13:58.074278-0400 Wood Factory - Gerenciador[1241:101761] -[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0 2017-09-21 07:13:58.478223-0400 Wood Factory - Gerenciador[1241:101761] [General] -[Wood_Factory___Gerenciador.FotoProduto setFoto:]: unrecognized selector sent to instance 0x6080000055a0 2017-09-21 07:13:58.482745-0400 Wood Factory - Gerenciador[1241:101761] [General] ( 0 CoreFoundation 0x00007fff930452cb exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffa7e5d48d objc_exception_throw + 48 2 CoreFoundation
0x00007fff930c6f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fff92fb7755 ___forwarding_
+ 1061 4 CoreFoundation 0x00007fff92fb72a8 _CF_forwarding_prep_0 + 120 5 Wood Factory - Gerenciador 0x000000010003e68c _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_ + 1948 6 Wood Factory - Gerenciador 0x000000010003ee78 _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_TA + 88 7 Wood Factory - Gerenciador 0x000000010000ba01 _T0So13NSApplicationC13ModalResponseVIxy_ADIyBy_TR + 49 8 AppKit 0x00007fff911b78b9 -[NSSavePanel _didEndSheet:returnCode:contextInfo:] + 95 9 AppKit 0x00007fff90d25b84 -[NSWindow _endWindowBlockingModalSession:returnCode:] + 308 10 AppKit 0x00007fff911ba073 -[NSSavePanel ok:] + 461 11 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 12 AppKit 0x00007fff91232721 -[NSApplication(NSResponder) sendAction:to:from:] + 456 13 AppKit 0x00007fff90d16cc4 -[NSControl sendAction:to:] + 86 14 AppKit 0x00007fff90d16bec __26-[NSCell _sendActionFrom:]_block_invoke + 136 15 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 16 AppKit 0x00007fff90d16b44 -[NSCell _sendActionFrom:] + 128 17 AppKit
0x00007fff90d59539 -[NSButtonCell _sendActionFrom:] + 98 18 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 53 19 AppKit 0x00007fff90d15426 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481 20 AppKit 0x00007fff90d59272 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798 21 AppKit 0x00007fff90d13ddb -[NSControl mouseDown:] + 832 22 AppKit
0x00007fff913ae24f -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341 23 AppKit 0x00007fff913aaa6c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942 24 AppKit 0x00007fff913a9f0a -[NSWindow(NSEventRouting) sendEvent:] + 541 25 AppKit 0x00007fff9122e681 -[NSApplication(NSEvent) sendEvent:] + 1145 26 AppKit 0x00007fff90aa9427 -[NSApplication run] + 1002 27 AppKit
0x00007fff90a73e0e NSApplicationMain + 1237 28 Wood Factory - Gerenciador 0x000000010005038d main + 13 29 libdyld.dylib
0x00007fffa8743235 start + 1 )

最佳答案

解决方案是创建一个 PFObject 的子类。

import Cocoa

import Parse

class FotoProduto: PFObject, PFSubclassing {

@NSManaged var foto: PFFile?
@NSManaged var categorias: [String]
@NSManaged var imagemCapa: Bool

override init() {
super.init()
}

init(foto: PFFile, categorias: [String]) {
super.init()

self.foto = foto
self.categorias = categorias
self.imagemCapa = false
}

static func parseClassName() -> String {
return "FotoProduto"
}
}

关于Swift OSX - 设置值时无法识别的选择器发送到 NSObject 子类上的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46342673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com