class choiceView:UIViewController,UITableViewDataSource,UITableViewDelegate{
@IBOutlet weak var userTableView: UITableView!
var refreshControl = UIRefreshControl()
var dataArray:[JSON]=[]
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
userTableView.delegate=self
userTableView.dataSource=self
refreshControl.addTarget(self, action: “refreshData”, forControlEvents: UIControlEvents.ValueChanged)
refreshControl.attributedTitle = NSAttributedString(string: “松手刷新新闻”)
userTableView.addSubview(refreshControl)
refreshData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// 刷新数据
func refreshData() {
netManage.request(.GET,url+”/v1/userstocknew”)
.responseJSON{ get in
let get_data=JSON(get.result.value!)[“stockList”]
self.dataArray=get_data.array!
self.userTableView.reloadData()
self.refreshControl.endRefreshing()
}
}
// UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let ut=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: “cell”)
let stockData=JSON(self.dataArray)
ut.textLabel?.text=stockData[indexPath.row][“name”].stringValue
let one_data=stockData[indexPath.row][“price”].stringValue+” “+stockData[indexPath.row][“floper”].stringValue
ut.detailTextLabel?.text=one_data
return ut
}
}
发表评论