0
下面的代碼正常工作,但「for」塊不起作用 所以「TableView」到數據中沒有添加。TableView不工作在迅速幫助我請
我該如何解決這個問題?
class ViewController: UITableViewController {
var NumberOfRows = 0
var BaslikArray = [String]()
var GonderenArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
parseJSON()
}
func parseJSON(){
let myUrl = NSURL(string: "http://10.10.5.1/mjson.php");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
let postString = "istek=pmliste&[email protected]&sifre=70c5fb2837e3edf992674a06fc876920&salt=sMb&tt=1";
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil
{
print("error=\(error)")
return
}
let readableJSON = JSON(data: data!, options: NSJSONReadingOptions.MutableContainers, error: nil)
self.NumberOfRows = readableJSON["pm"].count
for var i = 0; i < self.NumberOfRows; i++ {
let aa = readableJSON["pm"][i]["baslik"].string!
self.BaslikArray.append(aa)
NSLog("\(readableJSON["pm"][i]["baslik"].string!)")
}
}
task.resume()
}
override func tableView(tableView: UITableView, numberOfRowsInSection sesction: Int) -> Int {
return NumberOfRows
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell" , forIndexPath: indexPath) as UITableViewCell
if BaslikArray.count != 0 {
cell.textLabel?.text = BaslikArray[indexPath.row]
}
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
self.BaslikArray.append(aa)此代碼在此處不起作用。 – pirpirim