Uygulamamda Singleton sınıfını kullanarak, bir json dizisi oluşturdunuz. sayımı her zaman "0" dırUICollectionViewCell sayısı her zaman geri dön 0
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print("Count: ",InsuranceManager.sharedInstance.InsTypeListArray.count) // Output Count : 0
return InsuranceManager.sharedInstance.InsTypeListArray.count
}
şöyle UICollectionView i paylaşılan öneğiyle Singleton sınıf döner. Toplama görünümü hücreleri displaying.The tekil sınıf olmadıklarını Yani:
import UIKit
class InsuranceManager {
static let sharedInstance = InsuranceManager()
var InsTypeListArray = [InsuranceType]()
var TypeArray = [InsuranceType]()
var CompListArray = [Companies]()
func getInsuranceDetails() {
if let path = NSBundle.mainBundle().pathForResource("type", ofType: "json") {
do
{
let data = try NSData(contentsOfURL: NSURL(fileURLWithPath: path), options: NSDataReadingOptions.DataReadingMappedIfSafe)
let jsonObj = JSON(data: data)
if jsonObj != JSON.null
{
print("jsonData:\(jsonObj)")
if let items = jsonObj["type"].array
{
// Removing the old data from Insurance type array
self.InsTypeListArray.removeAll()
for item in items
{
var type = InsuranceType()
type.id = item["id"].int
type.name = item["name"].string
type.selectedQuantity = 1
type.imageName = item["imageName"].string
// Adding new data into Insurance type array
self.InsTypeListArray.append(type)
}
print("Insurance List Array Count:\(self.InsTypeListArray.count)")
}
}
else {
print("could not get json from file, make sure that file contains valid json.")
}
}
catch let error as NSError {
print(error.localizedDescription)
}
}
else {
print("Invalid filename/path.")
}
}
}
sayım değeri 0 böylece toplama görünümü hücreleri boş olur.
struct InsuranceType
{
var id: Int?
var name: String?
var selectedQuantity: Int?
var imageName: String?
}
Benim json dosyasıdır: json benim değerler "tip" dosyası dayanarak
{
"type": [
{
"id": 1001,
"name": "Vehicle",
"imageName": "vehicle"
},
{
"id": 1002,
"name": "Health",
"imageName": "health"
},
{
"id": 1003,
"name": "Life",
"imageName": "life"
},
{
"id": 1004,
"name": "House",
"imageName": "home"
},
{
"id": 1005,
"name": "Legal Protection",
"imageName": "legal"
},
{
"id": 1006,
"name": "Travel",
"imageName": "travel"
}
]
}
UICollectionView görüntülemek istediğiniz. Lütfen bana, kodumdaki asıl sorun nedir?