Masaüstümüzü swiftyjson kullanarak url'ye giriş yaptığım json verileriyle doldurmaya çalışıyorum. Sorunla karşı karşıya kaldığım sorun ise, şehri dizideki kavrama im değil, ancak tablo görünümünde kullandım göstermiyor. Nasıl düzeltebilirim? (url'yi tıklayarak jsonumun veri yapısını kontrol edebilirsiniz). Eğer şehirlerin dizinizi oluşturduktan sonraTablo görünümünde Swifyjson
import UIKit
import SwiftyJSON
import Alamofire
class ViewController: UIViewController , UITableViewDelegate ,UITableViewDataSource {
@IBOutlet var tableview: UITableView!
var data = [String]()
var numberofRows = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Alamofire.request(.GET, "http://android.goidx.com/search")
.responseJSON {(response) -> Void in
if let value = response.result.value {
let json = JSON(value)
for (index,json):(String, JSON) in json {
//Do something you want
self.numberofRows = json["city"].count
let city = json["city"].string! as String
self.data.append(city)
print(json["city"].stringValue)
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numberofRows
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell" , forIndexPath: indexPath) as UITableViewCell
if data.count != 0 {
cell.textLabel?.text = data[indexPath.row]
}
return cell
}
}
hayır işe yaramıyor –
Şehir, json'a bakmadan sayımın doğru olmayacağı bir dizi değil. Bunun yerine self.data.count değerini döndürmek için numberOfRowsInSection değerini değiştirin. –
Evet! Ben bunu self.data.count için değiştirdim ama tablo görünümünde görünmüyordu. Bu, yazdırdığımda veri dizisinin çıktısıdır, bana çok sayıda dizi veriyor. ["Diğer İlçe - ABD'de Değil"] ["Diğer İlçe - ABD'de Değil", "Homestead"] ["Diğer İlçe - ABD'de Değil", "Homestead", "Doral"] ["Diğer İlçe - ABD'de Değil", "Homestead", "Doral "," Hallandale "] –