我試圖讓swfityjson和阿爾莫在Xcode 8 工作就像郵局在此頁:Swift3 Alamofire SwiftyJSON得到外界的數據founcion
Showing JSON data on TableView using SwiftyJSON and Alamofire
但我不能得到的數據自。 這幫了我一些,但我堅持與伯爵。有人請幫助我,因爲我是新來的迅速,並花了一天的時間,試圖瞭解如何獲得行數和數據出almo函數。
import UIKit
import Alamofire
import SwiftyJSON
class TableViewController: UITableViewController {
var names = [String]()
var rowCount = [Int]()
var tableTitle = [String]()
typealias JSONStandard = [String : AnyObject]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func callAlamo(){
let url = "http://xxxxxx/xxxx/xxxxxx.php"
//let id = UserDefaults.standard.string(forKey: "UserDefaults")
Alamofire.request(url).responseJSON{(respones)->Void in
if let value = respones.result.value{
let json = JSON(value)
let rows = json["items"].arrayValue
for anItem in rows {
let title: String? = anItem["SupplierName"].stringValue
self.tableTitle.append(title!)
//print(self.tableTitle.count)
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
// let isUserLoggedin = UserDefaults.standard.boll(forKey: "userLogIn")
let ststus = UserDefaults.standard.string(forKey: "userLogIn")
if ststus == "false" {
self.performSegue(withIdentifier: "loginView", sender: self)
}else{
callAlamo()
}
}
@IBAction func logout(_ sender: AnyObject) {
UserDefaults.standard.set(false, forKey: "userLogIn")
UserDefaults.standard.synchronize()
self.performSegue(withIdentifier: "loginView", sender: self)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print (tableTitle)
return self.tableTitle.count
}
}
我無法獲得tableTitle.count。謝謝!
重新加載tableview中後得到的迴應 – Ragul