简体   繁体   English

TableView在ViewController中不显示数据:Swift

[英]TableView not displaying data in ViewController: Swift

Everything was working fine when I had it in an entire TableViewController, but because I need to have a dropdown menu I switched over to a basic ViewController to have more flexibility. 当我将其放在整个TableViewController中时,一切都运行良好,但是由于需要下拉菜单,因此我切换到基本的ViewController,以具有更大的灵活性。 Haven't been able to display the data since. 此后一直无法显示数据。

I think I have all my bases covered. 我想我已经涵盖了所有基础。 It is a tableView inside a viewController. 它是viewController内部的tableView。 Delegate and dataSource are set from the tableView to my viewController. Delegate和dataSource从tableView设置为我的viewController。 The cell identifier is correctly set to "cell". 单元标识符正确设置为“单元”。 The data is being pulled and can confirm it is in the collectionsAndArrays object. 数据将被提取,并可以确认它在collectionsAndArrays对象中。

Any help would be great, thanks. 任何帮助将是巨大的,谢谢。

edit: added self.collectionTableView!.reloadData() and still not working 编辑:添加了self.collectionTableView!.reloadData()仍然无法正常工作

import UIKit

class ImagesTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var collectionInfo: NSArray = DataManager.getUserCollections()
var items: NSMutableArray = []

@IBOutlet weak var collectionTableView: UITableView!
@IBOutlet weak var menuView: UIView!

override func viewDidLoad() {
    super.viewDidLoad()


    APIManager().getData() { completed in
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            if completed {


                self.items = NSMutableArray(array: self.collectionInfo)


            } else {
                //do something else
            }
        })
        // Do any additional setup after loading the view.
    }
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    var numberOfCollections: Int = self.items.count

    return numberOfCollections

}


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

    var collectionsAndArrays = PSCollection()
    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")


    // Configure the cell...

    collectionsAndArrays = self.items[indexPath.row] as! PSCollection
    cell.textLabel!.text = collectionsAndArrays.name
    cell.detailTextLabel!.text = collectionsAndArrays.created_at


    return cell
}
}

Try this 尝试这个

override func viewDidLoad() {
super.viewDidLoad()


APIManager().getData() { completed in
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        if completed {


            self.items = NSMutableArray(array: self.collectionInfo)
            self.collectionTableView.reloadData()


        } else {
            //do something else
        }
    })
    // Do any additional setup after loading the view.
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM