任何人都可以解释为什么当在.gif中选择步进器时滚动视图自动向上滚动当按下2p tuxedo时出现这种情况(所有单元格都不会出现)下面是视图控制器(Service1ViewController)的代码,代码为单元格(Service1TableViewCell)和init函数的代码(服务)
我使用提供的答案更新了代码,下面开始出现的问题是更新的代码以及更新的.gif文件。
[![更新的问题] [1]] [1]
Service1ViewController
class Service1ViewController: UIViewController {
@IBOutlet weak var Service1IMG: UIImageView!
@IBOutlet weak var service1TableView: UITableView!
@IBOutlet weak var service1Total: UILabel!
var Dry: [Service1] = []
var orderCount = [Int : Int]()
override func viewDidLoad() {
super.viewDidLoad()
Dry = Options()
for i in 0...30// TotaL number of rows
{
orderCount[i] = 0 // DEFAULT order count will be 0
}
}
func Options() -> [Service1]{
var dryOptions: [Service1] = []
let option1 = Service1(titled: "Pants", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option2 = Service1(titled: "Shirt", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option3 = Service1(titled: "Polo Shirt", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option4 = Service1(titled: "Polo (Long Sleeves)", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option5 = Service1(titled: "Shorts", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option6 = Service1(titled: "Tie", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option7 = Service1(titled: "2 Pc Tuxedo", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option8 = Service1(titled: "Jacket", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option9 = Service1(titled: "Men's 2pc Suite", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option10 = Service1(titled: "Blouse", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option11 = Service1(titled: "Skirt", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option12 = Service1(titled: "Women's 2pc Suite", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option13 = Service1(titled: "Dress", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option14 = Service1(titled: "Sweater", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option15 = Service1(titled: "Semi Formal Dress", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option16 = Service1(titled: "Customer Bag", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option17 = Service1(titled: "Jumpsuite", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option18 = Service1(titled: "Over Coat", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option19 = Service1(titled: "Rain Coat", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option20 = Service1(titled: "Skirt W/Pleats", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option21 = Service1(titled: "Robe", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option22 = Service1(titled: "Comforter /King", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option23 = Service1(titled: "Comforter /Queen", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option24 = Service1(titled: "Comforter /Twin", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option25 = Service1(titled: "Long Jacket", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option26 = Service1(titled: "Winter Jacket", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option27 = Service1(titled: "Men's 3pc Suite", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option28 = Service1(titled: "Women's 3pc Suite", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option29 = Service1(titled: "Overall", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option30 = Service1(titled: "Table Cloth/Small", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
let option31 = Service1(titled: "Shawl", pricing: 5.29, image: #imageLiteral(resourceName: "DryCleaning"))
dryOptions.append(option1)
dryOptions.append(option2)
dryOptions.append(option3)
dryOptions.append(option4)
dryOptions.append(option5)
dryOptions.append(option6)
dryOptions.append(option7)
dryOptions.append(option8)
dryOptions.append(option9)
dryOptions.append(option10)
dryOptions.append(option11)
dryOptions.append(option12)
dryOptions.append(option13)
dryOptions.append(option14)
dryOptions.append(option15)
dryOptions.append(option16)
dryOptions.append(option17)
dryOptions.append(option18)
dryOptions.append(option19)
dryOptions.append(option20)
dryOptions.append(option21)
dryOptions.append(option22)
dryOptions.append(option23)
dryOptions.append(option24)
dryOptions.append(option25)
dryOptions.append(option26)
dryOptions.append(option27)
dryOptions.append(option28)
dryOptions.append(option29)
dryOptions.append(option30)
dryOptions.append(option31)
return dryOptions
}
}
extension Service1ViewController: UITableViewDataSource,UITableViewDelegate{
@IBAction func stepperAcn(_ sender: UIStepper) {
let cellPosition = sender.convert(CGPoint.zero, to: service1TableView)
let indPath : IndexPath = service1TableView.indexPathForRow(at: cellPosition)!
orderCount[indPath.row] = Int(sender.value)
service1TableView.beginUpdates()
service1TableView.reloadRows(at: [indPath], with: UITableViewRowAnimation.none)
service1TableView.endUpdates()
//service1TableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Dry.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Dry1 = Dry[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "Service1Cell") as! Service1TableViewCell
cell.setService1(Dry: Dry1)
cell.quantityStepper.tag = indexPath.row
cell.stepperLabel.text = String(orderCount[indexPath.row]!) // PASS VALUES TO LABEL
cell.quantityStepper.value = Double(orderCount[indexPath.row]!) // PASS VALUES TO STEPPER
cell.selectionStyle = .none
return cell
}
// add function to collect (didSelectRowAt) and send selected data to cart
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
}
Service1TableViewCell
class Service1TableViewCell: UITableViewCell {
@IBOutlet weak var quantityLabel: UILabel!
@IBOutlet weak var quantityStepper: UIStepper!
@IBOutlet weak var Service1image: UIImageView!
@IBOutlet weak var serviceTitle: UILabel!
@IBOutlet weak var pricingInfo: UILabel!
@IBOutlet weak var stepperLabel: UILabel!
func setService1(Dry: Service1){
Service1image.image = Dry.service1image
pricingInfo.text = Dry.service1Pricing.description
serviceTitle.text = Dry.service1Title
}
//save data from each cell and multiply for total service
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
服务
class Service
{
var title: String
var description: String
var image: UIImage
init(titled: String, description: String, image: UIImage)
{
self.title = titled
self.description = description
self.image = image
}
}
答案 0 :(得分:1)
此问题可能会从重新加载整个TableView上升。我们选择reloadRows
@IBAction func stepperAcn(_ sender: UIStepper) {
let cellPosition = sender.convert(CGPoint.zero, to: service1TableView)
let indPath : IndexPath = service1TableView.indexPathForRow(at: cellPosition)!
orderCount[indPath.row] = Int(sender.value)
service1TableView.beginUpdates()
service1TableView.reloadRows(at: [indPath], with: UITableViewRowAnimation.none)
service1TableView.endUpdates()
//service1TableView.reloadData()
}