の値を掛けることはできません.PickerViewsの値を取得しようとしていますが、ボタンアクションでそれを掛けようとしていますが、エラーが出ます。しかし悲しいことに、私はまだ私がやろうとしていることを達成できませんでした。 - ピッカービューの値を乗算し、TextViewのUIpickerView Swift 3
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.
}
}
'Double'に' UILabel'を乗じていますか? – Eendje
私はコードを更新しました。 – Sadin