【发布时间】:2015-12-21 17:51:54
【问题描述】:
我已按照Ray Wenderlich 的教程进行操作。但是我没有将数组直接放入 UITableView。现在将 JSON 加载到 UITableView 大约需要 20 秒。但是在控制台日志中,阵列是直接可用的。我正在使用 Swift 2.0。
@IBOutlet var tableView: UITableView!
let textCellIdentifier = "CoffeeLocations"
var apps : [String] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
// Do any additional setup after loading the view.
DataManager.getTopAppsDataFromItunesWithSuccess { (iTunesData) -> Void in
let json = JSON(data: iTunesData)
if let appArray = json[].array {
for appDict in appArray {
let appName: String? = appDict["name"].string
self.apps += ["\(appName!)"]
}
print(self.apps) // Here he print directly to the console log
self.tableView.reloadData()
}
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return apps.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as! TableViewCell
let row = indexPath.row
cell.titleLabel!.text = apps[row]
//cell.detailLabel!.text = description[row] Later I want to add a second rule
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
错误日志(直接):
2015-09-24 09:45:31.493 TopApps[660:180190] 收到内存警告。 ["\'t Koffiehuisje"、"Caffee Allee | Stadsrestaurant"、"Ketelhuis"、"Monk Eindhoven"、"Radio Royaal"、"PopEi Food & Drinks"、"Tijdelijk 餐厅"、"NATLAB"、"Bagel & Juice”、“糕点俱乐部”、“Intellegentia ICE”、“Onder de leidingstraat”、“Keukenconfessies”]
数组中每一行的错误日志(20 秒后):
2015-09-24 09:46:09.579 TopApps[660:180231] 此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。 堆:( 0 核心基础 0x0000000182bb0f74 + 148 1 libobjc.A.dylib 0x00000001977a3f80 objc_exception_throw + 56 2 核心基础 0x0000000182bb0ea4 + 0 3 基础 0x0000000183bca5d8 + 88 4 基础 0x0000000183a4ca1c + 36 5 UIKit 0x000000018820b958 + 64 6 UIKit 0x00000001881022d8 + 240 7 UIKit 0x0000000188101b8c + 116 8 UIKit 0x0000000188101a18 + 504 9 UIKit 0x00000001884098e0 + 228 10 UIKit 0x0000000188100458 + 412 11 UIKit 0x00000001881fae14 + 1440 12 UIKit 0x00000001881efab8 + 216 13 UIKit 0x000000018810300c + 644 14 石英核心 0x0000000187909f14 + 148 15 石英核心 0x0000000187904b20 + 292 16 石英核心 0x00000001879049e0 + 32 17 石英核心 0x000000018790407c + 252 18 石英核心 0x0000000187903dd0 + 516 19 石英核心 0x0000000187932f48 + 236 20 libsystem_pthread.dylib 0x00000001981b21e8 + 584 21 libsystem_pthread.dylib 0x00000001981b1d60 + 136 22 libsystem_pthread.dylib 0x00000001981b1544 pthread_mutex_lock + 0 23 libsystem_pthread.dylib 0x00000001981b1028 start_wqthread + 4 )
【问题讨论】:
标签: ios json uitableview swifty-json