JSON数据的调用
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NetManager.GET(URLString, parameters: [“tag”:tag,”start”:0,”count”:10], success: { (responseObject) -> Void in
print(responseObject)
self.books = []
if let dict = responseObject as? [String:NSObject],array = dict[“books”] as? [[String:NSObject]]{
for dict in array{
self.books.append(Book(dict:dict))
}
self.tableView.reloadData()
}
}) { (error) -> Void in
print(error)
}
tableView.estimatedRowHeight = 100 //预估行高
tableView.rowHeight = UITableViewAutomaticDimension //tableview动态计算行高
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return books.count
} //返回tableView的行数
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let bookcell = tableView.dequeueReusableCellWithIdentifier(“BookCell”, forIndexPath: indexPath) as! BookCell
bookcell.configureWithBook(books[indexPath.row]) // 根据行号,返回数组中的数据值
return bookcell
}//填充数据
//BookCell.swift文件
func configureWithBook(book:Book){
//imageViewIcon.setResizeImageWith(book.image, width: imageViewIcon.frame.size.width)
imageViewIcon.sd_setImageWithURL(NSURL(string: book.image)) //加载图片
// rating.text = “”
lableTitle.text = book.title
var detail = “”
for str in book.author{
detail += (str + “/”)
}
lableDetail.text = detail + book.publisher + “/” + book.pubdate
}