ios - 类型名称的预期标识符

标签 ios swift

下面的代码给我错误:

expected identifier for type name

也许这可能是我应该自己处理的原因,因为我看到了一些帖子。但它没有用。

Xcode 谈论我的是哪种标识符? 我该如何解决?

如果我修复了这个错误,但还有更多错误,我应该使用 UITableViewController 而不是单独的 UIViewControllerUITableViewDelegate 吗?

import UIKit
import Parse

class Home: UIViewController, UITableViewDelegate,  {  //error here "expected identifier for type name"


    @IBOutlet weak var homepageTableView: UITableView!
    var imageFiles = [PFFile]()
    var imageText = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        var query = PFQuery(className: "Posts")
        query.orderByAscending("createdAt")
        query.findObjectsInBackgroundWithBlock { ( posts : [AnyObject]?, error : NSError?) -> Void in
            if error == nil {
                //불러오는데 성공
                for posts in posts! {
                    self.imageFiles.append(posts["imageFile"] as! PFFile)
                    self.imageText.append(posts["imageText"] as! String)
                    println(self.imageFiles.count)
                }

                /**reload the table **/
                self.homepageTableView.reloadData()
                println("reloaded")
            } else {
                println(error)
            }
        }
    }

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

    func tableView(tableView:  UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell : TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! TableViewCell

        //text
        cell.previewCommentLabel.text = imageText[indexPath.row]

        //image
        imageFiles[indexPath.row].getDataInBackgroundWithBlock({ ( imageData : NSData?, error : NSError?) -> Void in

            if imageData != nil {
                //ㅇㅋ
                var image = UIImage(data: imageData!)
                cell.previewImage.image = image
            }else {
                println(error)
                //no
            }
        })

        return cell
    }
}

最佳答案

您的类定义中有一个不需要的逗号(在 UITableViewDelegate 之后)。

改变:

class Home: UIViewController, UITableViewDelegate,  {  //error here "expected identifier for type name"

到:

class Home: UIViewController, UITableViewDelegate  {  //error here "expected identifier for type name"

使用 UITableViewController 而不是带有 UITableViewDelegateUIViewController 应该没有太大区别,因为您仍然必须实现相同的委托(delegate)方法。

但是,您必须实现 UITableViewDataSource 才能填充表格 View 。 UITableViewDelegate 用于处理行的选择(等)而不是显示它们。

重要的是,tableView:numberOfRowsInSection:tableView(tableView:cellForRowAtIndexPath:UITableViewDataSource 的一部分。

关于ios - 类型名称的预期标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32107940/

相关文章:

ios - 当您关闭并重新打开应用程序时,如何在 iOS 上保留 Firebase 连接?

ios - Xcode 中单个场景中的多个自定义 View

image - iOS @2x 拉长图像

ios - Restkit 0.20 实例化 NSManagedObject

swift - 执行核心数据的连接

initialization - Swift 子类化——如何覆盖 Init()

ios - Swift Xcode 6 在测试时给出 SIGABRT

ios - 在没有 nib 的情况下以编程方式实例化 UIViewController

swift - 我可以在作为参数传递的类型上专门化泛型函数吗?

arrays - 从数组值中查找 Firebase Child - xcode 8/swift 3