Reputation: 125
The below code is giving me the error:
expected identifier for type name
Maybe it could be the reason that I should handle with it with self, because I saw some post. but it didn't work.
What kind of identifier Xcode talks about me? And how can I fix it?
If I fixed this error, but there are more errors, should I work with a UITableViewController
rather than a separate UIViewController
and UITableViewDelegate
?
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
}
}
Upvotes: 2
Views: 3320
Reputation: 1926
You have a comma in your class definition that isn't needed (after UITableViewDelegate
).
Change:
class Home: UIViewController, UITableViewDelegate, { //error here "expected identifier for type name"
to:
class Home: UIViewController, UITableViewDelegate { //error here "expected identifier for type name"
Using a UITableViewController
instead of a UIViewController
with UITableViewDelegate
shouldn't make much difference, as you will still have to implement the same delegate methods.
However, you will have to implement UITableViewDataSource
in order to populate the table view. UITableViewDelegate
is for handling selection of rows (etc.) rather than displaying them.
Significantly, tableView:numberOfRowsInSection:
and tableView(tableView:cellForRowAtIndexPath:
are part of UITableViewDataSource
.
Upvotes: 7
Reputation: 17898
You have an extra comma there.
class Home: UIViewController, UITableViewDelegate, { //error here "expected identifier for type name"
Should be:
class Home: UIViewController, UITableViewDelegate { //error here "expected identifier for type name"
Upvotes: 2