簡體   English   中英

將未解析的標識符用於“自身”

[英]Use of unresolved identifier for “self”

我為我的PFQueryTableViewController子類化了viewController ,無論我在代碼中編寫self哪里,都會遇到相同的錯誤。

我以為PFQueryTableViewController不會給我錯誤,但是我將在這里提供我的代碼。

我不確定為什么會有這個問題,因為我之前使用過這個確切的代碼,而現在卻收到了錯誤。 是否有任何缺失或應添加的代碼以消除此錯誤。

    import UIKit
    import Parse
    import CoreLocation


    @available(iOS 8.0, *)
    class ResponseViewController: PFQueryTableViewController, UITextFieldDelegate {

    var Reply:NSMutableArray! = NSMutableArray()
    var post:PFObject?


    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        let query = PFQuery(className: "Test")


            query.limit = 200;
            query.addAscendingOrder("createdAt")

            query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in

                if error == nil{
                    for object in objects!{
                        let post : PFObject = object as! PFObject
                        self.Reply.addObject(post)
                    }

                    let array : NSArray = self.Reply.reverseObjectEnumerator().allObjects
                    self.Reply = NSMutableArray(array: array)

                    self.tableView.reloadData()

                }
            }

        }}

    func objectAtIndexPath(indexPath: NSIndexPath!) -> PFObject? {
    var obj : PFObject? = nil
    if(indexPath.row < self.objects!.count){
        obj = self.objects![indexPath.row] as? PFObject
    }

    return obj
}



       func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return post.count
        }



     func numberOfSectionsInTableView(tableView: UITableView) -> Int {
            return 1
        }

    func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
        let cell = tableView!.dequeueReusableCellWithIdentifier("responseCell", forIndexPath: indexPath!) as! ResponseCell
          if let respondersPost : PFObject = self.Reply.objectAtIndex(indexPath!.row) as! PFObject {
        cell.responder.text = object["userName"] as? String
        cell.respMessage.text = object["message"] as? String

        cell.respMessage.numberOfLines = 0
        let score = object[("count")] as! Int
        cell.likeCount.text = "\(score)"

        //    cell.userImage.image = object["photo"] as! PFFile
        cell.respMessage.text = respondersPost.objectForKey("message") as! String

        return cell
    }



    func sendReply(sender: AnyObject) {
                    let testObj = PFObject(className: "Responses")
                    print("***///let testObj = PFObject(className: \"Responses/***")


            //        testObj["location"] = PFGeoPoint(latitude: currLocation!.latitude , longitude: currLocation!.longitude)
                    testObj["count"] = 0
                    testObj["message"] = self.textfield.text
                    testObj.saveInBackgroundWithBlock { (success:Bool, error :NSError?) -> Void in
                        if error == nil
                        {
                            print("***///detail is saved///***")
                            self.dismissViewControllerAnimated(true, completion: nil)
                        }

        }

PFQueryTableViewController是ParseUI SDK的一部分,因此,如果不將其導入視圖中,則會遇到問題。

正確的方法來使用PFQueryTableViewController

import UIKit
import ParseUI

class WaitListTVC: PFQueryTableViewController {

override init(style: UITableViewStyle, className: String?) {
    super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!

    self.parseClassName = CoursetyConstants.kWaitListClassName
    self.pullToRefreshEnabled = true
    self.paginationEnabled = true
}

override func queryForTable() -> PFQuery {
    let query = PFQuery(className: self.parseClassName!)
    //query.whereKey("user", equalTo: PFUser.currentUser()!)
    return query
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM