我遇到了似乎无法修复的错误。错误在我的fetchPosts()函数中。我可以使用我的方法文件夹中的Post数组,但是它有一些属性,所以我可以这样做。
class UIFeedViewControllerTableViewController: UITableViewController {
var posts: [Post]?
struct Storyboard {
static let postCell = "PostCell"
static let postHeaderCell = "PostHeaderCell"
static let postHeaderHeight : CGFloat = 57.0
static let postCellDefaultHeight : CGFloat = 578.0
}
override func viewDidLoad() {
super.viewDidLoad()
self.fetchPosts()
tableView.estimatedRowHeight = Storyboard.postCellDefaultHeight
tableView.rowHeight = UITableView.automaticDimension
tableView.separatorColor = UIColor.clear
}
func fetchPosts()
{
//this could be from Firebase, Amazon, whatever
** self.posts = Post.fetchPosts()**
self.tableView.reloadData()
}
}
extension UIFeedViewControllerTableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
if let posts = posts {
return posts.count
}
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let _ = posts {
return 1
} else {
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.postCell, for: indexPath) as! PostCell
cell.Post = self.posts?[indexPath.row]
cell.selectionStyle = .none
return cell
}
}
它指出我的错误是“类型'Post'没有成员'fetchPosts'。任何帮助都将非常有用!