我正在尝试创建一个返回包含许多数据的 Multi-up 表的应用程序,但我认为我需要一个完成处理程序。
// object data :
import Foundation
class RepoSwiftyJSON:NSObject {
let _userId:String!
let _title:String!
init(userid:String , title:String){
self._userId = userid
self._title = title
}
}
表视图控制器
import UIKit
import Alamofire
import SwiftyJSON
class TableViewController: UITableViewController {
var parkData:[JSON] = []
var aryId = [RepoSwiftyJSON]()
func getJSONData() {
let url = "http://jsonplaceholder.typicode.com/posts/"
Alamofire.request(.GET,url).responseJSON {response in
guard let data = response.result.value else {
let error = response.result.error
let alertController = UIAlertController(title: "Error", message:error?.localizedDescription, preferredStyle: .Alert)
let okAction = UIAlertAction(title: "Retry", style: .Default, handler: { (alert:UIAlertAction) -> Void in
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
self.getJSONData()
alertController.dismissViewControllerAnimated(true, completion: {})
})
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: {})
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
return
}
let json = JSON(data)
self.parkData = json.array!
for key in self.parkData{
let DataArray:RepoSwiftyJSON = RepoSwiftyJSON ()
let userId = key["userId"].intValue
let title = key["title"].string
DataArray._userId = userId
DataArray._title = title
self.aryId.append(DataArray)
}
self.showJSONData()
}
}
func showJSONData() {
//println(parkData)
tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
getJSONData()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let numberOfRows: Int = self.aryId.count {
return numberOfRows
} else {
return 0
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("masterCell", forIndexPath: indexPath)
let rowData:JSON = aryId[indexPath.row]
cell.textLabel?.text = rowData._title
cell.detailTextLabel?.text = String(rowData._userId)
print(rowData)
return cell
}
但是当我运行该应用程序时,出现以下错误:
Missing argument for parameter 'userid'
在线路呼叫线路let DataArray:RepoSwiftyJSON = RepoSwiftyJSON ()
和
Cannot subscript a value of type '[RepoSwiftyJSON]'
在行let rowData:JSON = aryId[indexPath.row]
我做错了什么?