Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 无法调用KYDrawer抽屉控制器中的任何内容_Swift - Fatal编程技术网

Swift 无法调用KYDrawer抽屉控制器中的任何内容

Swift 无法调用KYDrawer抽屉控制器中的任何内容,swift,Swift,我使用创建了一个抽屉视图,它是一个UIViewController和tableview以及一些内容,我正在调用一个API来填充tableview,但我无法在抽屉视图控制器内显示或调用该API函数 这是我的代码: import UIKit import Alamofire import SwiftyJSON class DrawerViews: UIViewController, UITableViewDelegate, UITableViewDataSource { let cate

我使用创建了一个抽屉视图,它是一个
UIViewController
tableview
以及一些内容,我正在调用一个API来填充tableview,但我无法在抽屉视图控制器内显示或调用该API函数

这是我的代码:

import UIKit
import Alamofire
import SwiftyJSON

class DrawerViews: UIViewController, UITableViewDelegate, UITableViewDataSource {

    let categoriesUrl = "https://stagecmsbmncapi.projectpresent.biz/client/categories/"

    public var tag_Names: String{ return UserDefaults.standard.string(forKey: "name") ?? "" }


    @IBOutlet weak var tableView: UITableView!

    var data = [[String: AnyObject]]()

    override func viewDidLoad() {
        super.viewDidLoad()
        getCategories()

        // Do any additional setup after loading the view.
    }
    func getCategories() {
        Alamofire.request(categoriesUrl).responseJSON { (response) in
            if ((response.result.value) != nil) {
                var jsonResult = JSON(response.result.value!)
                print(jsonResult)
                if let da = jsonResult["result"].arrayObject
                {
                    self.data = da as! [[String : AnyObject]]

                }

            }
        }
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {
        case 0:
            return 1
        case 1:
            return 2
        case 2 :
            return 5
        default:
            return 1
        }
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        switch indexPath.section {
        case 0:
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! NameCell
            return cell
        case 1:
            let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! CatgoryCell
            return cell1
        case 2 :
            let cell2 = tableView.dequeueReusableCell(withIdentifier: "cell3", for: indexPath) as! SupportCell
            return cell
        default :
            print("Defaults")
        }
        return cell
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0:
            return 100
        case 1:
            return 60
        case 2 :
            return 60
        default:
            return 700
        }
    }
}
在ViewDidDisplay中调用getCategories()函数