【问题标题】:Use of undeclared type issue使用未声明的类型问题
【发布时间】:2015-02-15 17:52:27
【问题描述】:

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

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

【问题讨论】:

  • allEntriesvariable 而不是 type,因此 let cellsForSection: [allEntries] = ...... as allEntries 根本没有意义。你期望它做什么?
  • 试图将 allEntries 数组作为单元格返回,这一切都错了吗?

标签: ios iphone swift parse-platform


【解决方案1】:

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

as allEntries

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

【讨论】:

  • 更改为 - 覆盖 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell cell.textLabel!。 text = allEntries[indexPath.row] return cell } --- 但现在给出致命错误:Cannot index empty buffer (lldb) debugging error at line -> cell.textLabel!.text.......row]跨度>
  • 任何关于使用返回数组创建表格的资源的想法或指示 - 不只是单元格标签将不胜感激。
  • 您必须返回单个单元格,而不是 cellForRowAtIndexPath 中的数组。我建议查看编程指南:guide
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
  • 2018-08-03
  • 2017-12-27
  • 2017-02-21
  • 2018-12-28
  • 2015-04-15
相关资源
最近更新 更多