【问题标题】:Cloudkit , Unrecognized Selector [duplicate]Cloudkit,无法识别的选择器[重复]
【发布时间】:2015-04-02 00:05:57
【问题描述】:

[CKRecord stringForKey:]: 无法识别的选择器发送到实例 0x17412ece0'

我收到了上述错误,但不确定我需要做些什么来纠正它。我正在运行一个查询以将 CKAssets 返回到集合视图中以显示图片。我希望两个文本字段匹配,并且当它们匹配关联的图像以填充视图时。有人有什么建议吗?

    @IBOutlet var myCollectionView: UICollectionView!
let reuseIdentifier = "MyCell"

var matchedSelfie = [String]()

override func viewDidLoad() {
    super.viewDidLoad()
    let database = CKContainer.defaultContainer().publicCloudDatabase
    let container = CKContainer.defaultContainer()
    let publicDB = container.publicCloudDatabase
    let data = CKRecord(recordType: "theUsers")
    let text1 = data.valueForKey("text1")
    let text2 = data.valueForKey("text2")
    var predicate = NSPredicate(value: text1 === text2)
    let myQuery = CKQuery(recordType: "theUsers", predicate: predicate)

    var mySelfie = matchedSelfie

    publicDB.performQuery(myQuery, inZoneWithID: nil) {
        results, error in
        if error != nil {
            println(error)

        } else {
            for record in results{
                if let aselfie = record.stringForKey("selfie") { //Optional binding
                    mySelfie.append(aselfie) //Append to string array

                    mySelfie.append(aselfie)
                    return ()
                }

            }}}

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    //#warning Incomplete method implementation -- Return the number of sections
    return 1
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    //#warning Incomplete method implementation -- Return the number of items in the section
    return matchedSelfie.count
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = myCollectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell
    let image = UIImage(named: matchedSelfie[indexPath.row])
    cell.matchedSelfie.image = image
    // Configure the cell

    return cell
}

【问题讨论】:

    标签: ios swift uicollectionview cloudkit


    【解决方案1】:

    错误说明了这一点。密钥selfie 不存在。

    您必须检查密钥是否真的存在。如果key存在,可以尝试使用objectForKey

    let aselfie = record.objectForKey("selfie") as String
    

    【讨论】:

    • 好的,知道了。错误出现在先前的视图中。它不是将记录写入云套件。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多