首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Swift在设置值时发送给NSObject子类上的实例的不可识别的选择器

Swift在设置值时发送给NSObject子类上的实例的不可识别的选择器
EN

Stack Overflow用户
提问于 2017-09-21 11:23:51
回答 1查看 378关注 0票数 1

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

调用类的操作。

代码语言:javascript
运行
复制
@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类

代码语言:javascript
运行
复制
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木材厂0x00007fff930452cb exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffa7e5d48d objc_exception_throw + 48 2 CoreFoundation _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_ 0x00007ff930c6f04 -NSObject(NSObject) doesNotRecognizeSelector:+ 132 3 CoreFoundation 0x00007fff92f2f7755 ___forwarding_ + 1061 4 CoreFoundation 0x007ff9f92fb7a8 _CF_forwarding_prep_0 + 120 5木材厂- Gerenciador 0x000000010003e68c木材厂+ 1948 6木材厂-格伦西亚多0x000000010003ee78 _T026Wood_Factory___Gerenciador30GerenciarProjetoViewControllerC28selecionarFotosButtonClickedySo8NSButtonCFySo13NSApplicationC13ModalResponseVcfU_TA +887木材厂0x000000010000ba01 _T0So13NSApplicationC13ModalResponseVIxy_ADIyBy_TR +498 AppKit 0x00007fff911b78b9 -NSSavePanel _didEndSheet:returnCode:contextInfo:+ 95 9 AppKit 0x00007fff90d25b84 -NSWindow _endWindowBlockingModalSession:returnCode:+ 308 10 AppKit 0x00007fff911ba073 -NSSavePanel ok:+ 461 11 libsystem_trace.dylib 0x00007 fffa89753a7 _os_activity_initiate_impl+ 53 12 AppKit 0x00007fff91232721 -NSApplication(NSResponder) sendAction:to:from:+ 456 13 AppKit 0x00007ff90d16cc4 -NSControl sendAction:to:+ 86 14 AppKit 0x00007fff90d16bec _26-NSCell _sendActionFrom:_block_invoke + 136 15 libsystem_trace.dylib 0x00007fffa89753a7 _os_activity_initiate_impl + 5316 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 track老鼠:inRect:ofView:untilMouseUp:+ 2481 20 AppKit 0x00007 ff90d59272 -NSButtonCell Track老鼠:inRect:ofView:+ 798 21 AppKit 0x00007fff90d13ddb -NSControl mouseDown:+ 832 AppKit -NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:+ 6341 23 AppKit 0x00007fff913aaa6c -NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:+ 1942 24 AppKit 0x00007ff913a9f0a -NSWindow(NSEventRouting) sendEvent:+ 541 25 AppKit 0x0000007ff9122e681 -NSApplication(NSEvent) sendEvent:+ 1145 26 AppKit 0x00007ff90a9427 -NSApplication run + 1002 27 AppKit 0x00007fff90a73e0e NSApplicationMain + 1237 28木材厂- Gerenciador 0x000000010005038d main + 13 29 libdyld.dylib 0x00007fffa8743235启动+1)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-21 16:42:48

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

代码语言:javascript
运行
复制
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"
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46342673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档