所以我使用的是Swift 3。
如果我将limit
等于13或更少的元素,该应用程序可以正常工作。但如果我让它读取超过13,它就会崩溃。
以下是代码:
var CoolArray = [Event]()
var num = 0
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return CoolArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("Displaying the outputs using array[indexPath.row]")
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Cell
let oneRow = CoolArray[indexPath.row]
cell.name.text = oneRow.name
return cell
}
var CoolArray = [Event]()
var num = 0
override func viewDidLoad() {
let request =
FBSDKGraphRequest(graphPath: "/somefacebookpag/events",
parameters: ["fields": "name,cover,place,start_time,end_time,description, owner",
"limit":"10", ],
httpMethod: "GET")
request?.start { ( connection, result, error) in
if let array = result as? [String : AnyObject]{
if let fbData = array["data"] as? [[String : AnyObject]] {
print("working")
for event in fbData {
if let nameOfEvent = event["name"] as? String,
{
print("Read array \(self.num)")
self.num += 1
let anotherOne = Event(name: nameOfEvent)
self.CoolArray.append(anotherOne)
}
}
self.tableView.reloadData()
}
}
}
}
如果有帮助的话。在viewDidLoad中注释代码使其正常工作