使用未声明的类型问题

时间:2015-02-15 17:52:27

标签: ios iphone swift parse-platform

在我关于此代码选择示例的最后一个函数中,Xcode生成了“使用未声明类型'allEntries'错误。我已经查看了有关此主题的几篇帖子,但仍然存在问题。不确定将变量设为公共是这里的问题因为所有人都在同一个班级。

import UIKit

class AllEntriesTableViewController: UITableViewController {

var passedValue = ""
var allEntries = [String]()

override func viewDidLoad() {
    super.viewDidLoad()


    var user = PFUser.currentUser()
    let event = PFObject(className:"event")
    var query = PFQuery(className:"event")
    query.whereKey("user", equalTo: user)
    query.includeKey("category")
    let category = event["category"] as NSString
    query.findObjectsInBackgroundWithBlock {
    (objects: [AnyObject]!, error: NSError!) -> Void in
    if error == nil {
    // The find succeeded.
    self.allEntries.removeAll(keepCapacity: true)
    // Do something with the found objects
    for object in objects {
        var allEnt:String = object as String
        self.allEntries.append(allEnt)
        //self.allEntries.append(allEnt.category)
    }
    } else {
    // Log details of the failure
    NSLog("Error: %@ %@", error, error.userInfo!)
    }
    }



    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

     //Uncomment the following line to display an Edit button in the navigation bar for this view controller.
     //self.navigationItem.rightBarButtonItem = self.editButtonItem()
        }

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

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 3
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellsForSection: [allEntries] = sections[indexPath!.section] as Array
    return cellsForSection[indexPath!.row] as allEntries

1 个答案:

答案 0 :(得分:0)

allEntries是一个变量,而不是一个类。因此,像你最后一行的演员

as allEntries

不起作用。您必须从UITableViewCell中的cellForRowAtIndexPath类型返回一个对象。