【发布时间】:2015-08-20 07:28:55
【问题描述】:
我有一个带有按钮的视图(我们称之为视图 1)。单击按钮时,我向我的 API 发出 GET http 请求。它发回一组对象。
目前我正在尝试做的是,当用户按下 view 1 上的按钮时,响应数据将传递给 view 2 这是一个 tableView。然后用返回的数据填充表格视图单元格。
我将返回的 JSON 响应从视图 1 传递到视图 2,如下所示:
dispatch_async(dispatch_get_main_queue()) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("BioView") as! BioTableViewController
vc.bioArray = parseJSON
self.presentViewController(vc, animated: true, completion: nil)
}
其中 parseJSON 包含返回的 JSON 响应。
在视图 2 中,我有以下内容:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.bioArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("bioCell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
if bioArray.count > 0 {
let weatherSummary: AnyObject = bioArray[indexPath.row]
for x in bioArray {
if let id = x["employeeName"] as? String{
cell.textLabel?.text = id
}
}
}
return cell
}
问题:
表格视图不断重复返回的 JSON 数据中的最后一个值。见下文:
我的问题:
如何阻止值重复并显示响应数据中的所有值,当我单击 tableview 单元格时,它会转到另一个视图并显示与单击的单元格相关的所有详细信息。 em>
【问题讨论】:
标签: ios json swift uitableview