我正在尝试将标签连接到原型单元并成功返回。我这样做有些麻烦。我连接了MyCustomTableViewCell。应用程序中正式没有xCode检测到的“错误”。但是,当我运行它时,我只是回到空白表视图。在代码中进一步向下(从第二行到最后一行),我放下“print(”Hi!“)”以查看代码是否正在处理,以及“嗨!”在运行时不会出现在控制台中。这是我目前的代码:
import UIKit
class MyCustomTableViewCell: UITableViewCell {
@IBOutlet weak var personText: UILabel!
}
class UserFeedTableViewController: UITableViewController, ComposeViewControllerDelegate {
private var posts: [PFObject]? {
didSet {
tableView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Query for feeds
Downloader.sharedDownloader.queryForPosts()
// Add observers
NSNotificationCenter.defaultCenter().addObserver(self, selector: "queryFeeds:", name: queryNotification, object: nil)
tableView.estimatedRowHeight = 44
tableView.rowHeight = UITableViewAutomaticDimension
}
// Notification SEL
func queryFeeds(notification: NSNotification) {
posts = notification.object as? [PFObject]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "postSegue" {
let nav = segue.destinationViewController as! UINavigationController
let composeVc = nav.topViewController as! ComposeViewController
composeVc.delegate = self
}
}
func dismissComposeViewController(viewController: ComposeViewController) {
dismissViewControllerAnimated(true, completion: nil)
}
func reloadTableViewAfterPosting() {
dismissViewControllerAnimated(true, completion: nil)
Downloader.sharedDownloader.queryForPosts()
}
}
// Mark Table View Data Source
extension UserFeedTableViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts?.count ?? 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyCustomTableViewCell", forIndexPath: indexPath) as! MyCustomTableViewCell
// Configure the cell...
if let posts = posts {
let object = posts[indexPath.row]
cell.personText?.text = object["post"] as? String
cell.personText?.numberOfLines = 0
}
print("Hi!")
return cell
}
}
如何更改它以便返回单元格?
答案 0 :(得分:0)
仔细检查return posts?.count
。尝试return posts?.count ?? 0
到return 1
进行测试
更新:我删除了我的错误。
希望这可以提供帮助。