【发布时间】:2017-05-25 11:02:19
【问题描述】:
我有一个函数可以找到应该添加到堆栈视图中的星数。 stackview 位于表格单元格内,因此显示正确的评级,该评级是从 CoreData 检索的。但是,评分未显示。
函数...
func setRating(entry: Entry, ratingView: UIStackView) -> UIStackView{
for _ in 0..<Int(entry.rating) {
let image = UIImage(named:"ratingFilled")
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
NSLayoutConstraint(item: image!, attribute: .height, relatedBy: .equal, toItem: image!, attribute:.width, multiplier: 1.0, constant:0.0).isActive = true
ratingView.addArrangedSubview(imageView)
}
return ratingView
}
Tableview 单元格调用...
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ //creates rzeusable cell and assigns cell items
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
let entry = entries[indexPath.row]
cell.nameLabel?.text = entry.restaurantName
cell.ratingView = setRating(entry: entry, ratingView: cell.ratingView)
return cell
}
【问题讨论】:
标签: ios swift uitableview core-data