gpt4 book ai didi

swift - UIpickerView Swift 3 无法乘以值

转载 作者:行者123 更新时间:2023-11-28 06:22:52 28 4
gpt4 key购买 nike

我试图获取 pickerViews 值并将其乘以按钮操作,但它给了我错误,我尝试了不同的想法。但遗憾的是我仍然没有完成我想要完成的事情,我已经更新了代码以便更好地理解。- 乘以选择器 View 值并将其显示在 TextView 中

import UIKit

class ViewController: UIViewController, UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource {
@IBOutlet weak var productPrice: UITextField!
@IBOutlet weak var myPrice: UILabel!
@IBOutlet weak var pickerView: UIPickerView!
@IBOutlet weak var perlol: UILabel!
var distribTopp:Array = [String]()
var distribBottomm:Array = [String]()
var priceLabell:Array = [String]()
var titleBarr:Array = [String]()
var iconeImage:Array = [UIImage]()

override func viewDidLoad() {
titleBarr = ["Fees","","","Profit","Calculations",""]

distribTopp = ["Paypal Fee","Ebay Fee","Feeless Price","Profit","Price Increase","Percent Increase"]

distribBottomm = ["Takes 2.9% + $0.30","Takes 10%","Price Without Fees","Profit From Original Price","How much USD Added","Percentage of Increased Price"]

priceLabell = ["$0.00","$0.00","$0.00","$0.00","$0.00","0.00%"]

iconeImage = [UIImage(named: "home")!,UIImage(named: "home")!,UIImage(named: "home")!,UIImage(named: "home")!,UIImage(named: "home")!,UIImage(named: "home")!
]

pickerView.delegate = self
pickerView.dataSource = self


super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

var percentagesPicker = ["10%","20%","30%","40%","50%"]

// DataSource
func numberOfComponents(in pickerView: UIPickerView) -> Int {

return 1

}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

return percentagesPicker.count
}

// Delegate

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {


return percentagesPicker[row]

}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

// var thirtyone = Double(percentagesPicker[row])


perlol?.text! = percentagesPicker[row]

if perlol?.text! == "10%"{

let thirty = Double(3000/10000)
perlol?.text = String(thirty)
}
if perlol?.text! == "20%"{

perlol?.text = String(thirty)
}
if perlol?.text! == "30%"{

perlol?.text = String(thirty)
}
if perlol?.text! == "40%"{

perlol?.text = String(thirty)
}
if perlol?.text! == "50%"{

perlol?.text = String(thirty)
}

print(percentagesPicker[row])
print(perlol)


}


// var percenta = self.percentagesPicker[row]

var Duration = Double(0.30)
var ebayfeess = Double(0.1)
var paypalfeess = Double(0.029)
var profitsss = Double(100)
var thirty = Double(3000/10000)


@IBAction func clearBtn(_ sender: Any) {

priceLabell = ["$0.00","$0.00","$0.00","$0.00","$0.00","0.00%"]
myPrice.text = String("0.00")
productPrice.text = String("")

}

@IBAction func goCalcul(_ sender: Any) {



let productnum = Double(productPrice.text!)! // Original Price
let feess = Double(productnum * thirty + productnum) //New Listing Price
let paypalfs = Double(paypalfeess * feess + Duration)//Paypal Fees
let ebayfs = Double(ebayfeess * feess) // Ebay Fee
let profitss = Double(((feess/productnum) * profitsss) - profitsss) //Percent
let priceIncrease = Double(productnum * 3000/10000) // Price Increase
let buying = Double(feess - paypalfs - ebayfs) // Left with
let profitnow = Double(buying - productnum) // Profit

let decimalPaypal = NSString(format: "%.2f", paypalfs)
let decimalebay = NSString(format: "%.2f", ebayfs)
let decimalbuying = NSString(format: "%.2f", buying)
let decimalProfit = NSString(format: "%.2f", profitnow)
let decimalprice = NSString(format: "%.2f", priceIncrease)
let decimaloriginal = NSString(format: "%.2f", feess)
// let l = String(perlol?.text)
myPrice.text = String(decimaloriginal)
//perlol.text = Double(perlol?.text)
//print(perlol.text)

priceLabell = [String("-$\(decimalPaypal)"),String("-$\(decimalebay)"), String("$\(decimalbuying)"), String("+$\(decimalProfit)"), String("+$\(decimalprice)"),String("+\(profitss)%")]
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return distribTopp.count & distribBottomm.count & titleBarr.count & priceLabell.count

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "MenuTableViewCell") as! MenuTableViewCell
cell.imgLbl.image = iconeImage[indexPath.row]
cell.describTop.text! = distribTopp[indexPath.row]
cell.describBottom.text! = distribBottomm[indexPath.row]
cell.priceLabel.text! = priceLabell[indexPath.row]
cell.titleBar.text! = titleBarr[indexPath.row]


if cell.describTop.text! == "Paypal Fee"
{
cell.priceLabel?.textColor = UIColor.red
}
if cell.describTop.text! == "Feeless Price"
{
cell.priceLabel?.textColor = UIColor.blue
}
if cell.describTop.text! == "Profit"
{
cell.priceLabel?.textColor = UIColor.green
}

if cell.describTop.text! == "Price Increase"
{
cell.priceLabel?.textColor = UIColor.green
}

if cell.describTop.text! == "Percent Increase"
{
cell.priceLabel?.textColor = UIColor.green
}
if cell.describTop.text! == "Ebay Fee"
{
cell.priceLabel?.textColor = UIColor.red
}

return cell
}



func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

let cell:MenuTableViewCell = tableView.cellForRow(at: indexPath) as! MenuTableViewCell

if cell.describTop.text! == "Paypal Fee"
{

}

}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

最佳答案

“goCalcul”方法中的“perlol”是什么?根据它在 UIPickerView 委托(delegate)方法中的用法,它似乎是一个标签。如果是,您是否应该在进行乘法运算之前从标签中获取文本值并将其转换为某种百分比值?

关于swift - UIpickerView Swift 3 无法乘以值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42822811/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com