关于IOS 开发中 Json 数据 展示到 TableView 中的思路.
Json 如下
Optional({
address = "";
affectivestatus = "";
alipay = "";
bio = "";
birthcity = "";
birthcommunity = "";
birthdist = "";
birthprovince = "";
company = 11;
education = "";
gender = 0;
github = 87875;
graduateschool = "";
idcard = "";
idcardtype = "";
lookingfor = "";
nationality = "";
occupation = "";
position = "";
qq = "";
realname = "";
residecity = "";
residecommunity = "";
residedist = "";
resideprovince = "";
residesuite = "";
revenue = "";
site = "";
telephone = "";
uid = 1;
weixin = "";
zipcode = "";
})
需要展示成这样
import UIKit
import Alamofire
class WoGeenziliaoViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
//用户头像
@IBOutlet weak var woPortrait: UIImageView!
//用户名称
@IBOutlet weak var woName: UILabel!
//用户资料列表
@IBOutlet weak var woList: UITableView!
var abc = NSDictionary()
override func viewDidLoad() {
super.viewDidLoad()
woList.delegate = self
woList.dataSource = self
woPortrait?.layer.cornerRadius = 50
woPortrait?.layer.masksToBounds = true
woPortrait.image = UIImage(named: "portrait")
woList.separatorColor = UIColor(red: 239/255, green: 239/255, blue: 244/255, alpha: 1.0)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
//println(self.abc.count)
return self.abc.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellid = "FujinID"
var index = indexPath.row
var cell:Wo_GerenziliaoTableViewCell? = woList.dequeueReusableCellWithIdentifier(cellid) as? Wo_GerenziliaoTableViewCell
if(cell == nil){
cell = Wo_GerenziliaoTableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: cellid)
}
cell?.Project?.text = "555"
cell?.Value!.text = "123"
Alamofire.request(.GET, "http://localhost/yuanyuan_web/index.php?m=api&c=User&a=getUserDetailsData", parameters: ["uid":1]).responseJSON() { (_, _, jsonData, _) -> Void in
println(jsonData)
if var j = jsonData as? NSDictionary{
self.abc = j
//昵称
var username = j.valueForKey("username") as? String
//荣誉
// var
//猿类
var yuantype = j.valueForKey("yuantype") as? NSString
//个人签名
var bio = j.valueForKey("yuantype") as? NSString
//公司
var company = j.valueForKey("company") as? NSString
//地区
var residecity = j.valueForKey("residecity") as? NSString
//主页/博客
var site = j.valueForKey("site") as? NSString
//GitHub
var github = j.valueForKey("github") as? NSString
}
}
// cell?.Project?.text = FaxianListC[index]["Project"]
// cell?.Value!.text = FaxianListC[index]["Value"]
return cell!
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
return 40.0
}
}
醋11111
9 years, 2 months ago