전무 도착하지만 dispatch_async
에서 실행할 때 당신은 주 스레드에서 self.data
을 수정해야 tableViews 기능 numberOfRowsInSection
배열 GCD
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) {
self.data = self.dataOfJson("http://192.168.1.100/practice/studentCourseSelection.php?ID=\(NSUserDefaults.standardUserDefaults().objectForKey("currentUser")!)")
self.RefreshTableView()
}
func RefreshTableView()
{
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}
}
func dataOfJson(url:String) -> NSArray
{
var jsonArray : NSMutableArray = []
let data = NSData(contentsOfURL: NSURL(string : url)!)
jsonArray = try! NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as! NSMutableArray
return jsonArray
}
'return self.data.count'를'return self.data.count ?? 0' –
코드를 보여주세요! 'self.dataOfJson'은 무엇입니까? 당신의 코드는'numberOfRowsInSection'과 다른 두 가지 큰 질문을 어떻게 구현합니까? – matt
self.data가 nil 일 때 count를 nil로 호출하면 EXC_BAD_INSTRUCTION RED ERROR가 발생합니다. 당신은 체크하지 않아도된다. – Cruz