1
저는 신속하게 익숙해졌으며 http 요청에서 테이블을 채우려하고 있습니다.Http GET에서 스위프트 배열 만들기
배열은 요청 내에서 제대로 인쇄되지만 외부에서는 여전히 빈 배열을 제공하며 테이블을 채우지 않습니다.
제가 누락 된 항목을 파악할 수 없습니다.
어떤 도움
class affiliates: UIViewController, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
var tableData = [String]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
// Register custom cell
var nib = UINib(nibName: "vwTblCell3", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "cell3")
// Set the URL where we're making the request
let request = NSURLRequest(URL: NSURL(string: "https://***************")!)
// Perform the request
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{
(response: NSURLResponse?, data: NSData?, error: NSError?)-> Void in
// Get data as string
let str = NSString(data: data!, encoding: NSUTF8StringEncoding)
print(str!)
self.tableData.append(str as! String)
print(self.tableData)
}
);
print(self.tableData)
}
// 2
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.count
}
// 3
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell \t {
let cell: TblCell3 = self.tableView.dequeueReusableCellWithIdentifier("cell3") as! TblCell3
cell.lblAffiliate.text = tableData[indexPath.row]
return cell
}
// 4
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Row \(indexPath.row) selected")
}
// 5
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 70
}
}