get() 함수의 결과를 tableview에 보내려고합니다. 이 함수 내부의 결과는 Http 게시물에서 가져옵니다. 그래서 nsmutableurl 등을 사용하고 있습니다. 데이터 출력 콘솔에서 볼 수 있고 지금은 내 tableview에 원합니다. 내가 어떻게 할 수 있니?스위프트 : UITableView를 채우는 방법
나는이 코드 묶음을 가지고 있으며 데이터를 가져와 (출력 콘솔에서 볼 수 있음) 이제 테이블 뷰에서이 데이터를로드하려고합니다. 이 데이터를 테이블에 어떻게 전달할 수 있습니까?
func get(){
let request = NSMutableURLRequest(URL: NSURL(string: "http://myurl/somefile.php")!)
request.HTTPMethod = "POST"
let postString = "id=\(cate_Id)"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
guard error == nil && data != nil else { // check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}
let responseString = String(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
task.resume()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
i need the count of the rows here
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
land want to display the data inside each cell
}