【发布时间】:2016-06-02 09:26:58
【问题描述】:
我希望当我点击UITableView 行时
它将发送一个 ID 到下一个 UIView
ID获取表单json数据
我无法获得UITableView indexPath
有一些错误。
我该如何解决这个问题?
这是我的代码
func get(){
let url = NSURL(string: "http://test.php?id=01")
let data = NSData(contentsOfURL: url!)
values = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray
tableView1.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return values.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! SpecialCell
let maindata = values[indexPath.row]
cell.name.text = maindata["product"] as? String
cell.vintage.text = maindata["vintage"] as? String
ID = maindata["ID"] as? String
return cell;
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!){
if segue.identifier == "showWineDetail"{
if indexPath = self.tableView1.indexPathForSelectedRow{
let destination = segue.destinationViewController as! ViewController
destination = self.ID
}
}
}
}
【问题讨论】:
-
错误是什么?
标签: json swift uitableview segue