简体   繁体   中英

Use of unresolved identifier for “self”

I have a PFQueryTableViewController subclassed for my viewController and I'm getting the same errors wherever I write self in my code.

I thought that a PFQueryTableViewController wouldn't give me errors for that but I'll provide my code here.

I'm not sure why I have this issue because I've used this exact code before and now I'm receiving errors with it. Is there anything missing or code I should add to remove this error.

    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的一部分,因此,如果不将其导入视图中,则会遇到问题。

Proper way to use a 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM