程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)?

开发过程中遇到如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)的问题如何解决?下面主要结合日常开发的经验,给出你关于如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)的解决方法建议,希望对你解决如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)有所启发或帮助;

我正在开发一个基本应用程序,它有一个包含约 1400 个项目的 ListArray,每个项目有 3 个属性(icao呼号、图像)。它有 2 个出口:一个“textFIEld”和一个“标签”。使用我的自定义键盘(按钮),我可以在“textFIEld”中写入 3 个字符。如果这 3 个字符与我的 ListArray 的 icao 项目匹配,那么我希望 callsign 项目显示在我的“标签”中。有没有办法用“if”语句来做到这一点?我想在“标签”中看到“美国”。这是我所拥有的: my xcode and simulator screens

  @IBOutlet var ICAOtextFIEld: UITextFIEld!
@IBOutlet var callsigntextLabel: UILabel!

var updateDicAOtextFIEld = ""
var ListArray = [List]()

overrIDe func vIEwDIDLoad() {
    super.vIEwDIDLoad()
    setUpList()
}

private func setUpList() {

ListArray.append(List(icao: "AAB",callsign: "A-B-G",image: "BElgiUM"))
ListArray.append(List(icao: "AAC",callsign: "ARMYAIR",image: "UK"))
ListArray.append(List(icao: "AAF",callsign: "AZUR",image: "FRANCE"))
ListArray.append(List(icao: "AAL",callsign: "AMERICAN",image: "USA"))
}

@IBACtion func abcbutton(_ sender: UIbutton) {
    
    updateDicAOtextFIEld = ICAOtextFIEld.text! + sender.currenttitle!
    ICAOtextFIEld.text = updateDicAOtextFIEld
    
    if updateDicAOtextFIEld.count > 3 {
        ICAOtextFIEld.text = ""
    }
    
    if ICAOtextFIEld.text ==                           {
        
        callsigntextLabel.text = "            "
    }
    
}

解决方法

@IBACtion func abcButton(_ sender: UIButton) {

    updateDicAOtextField = ICAOtextField.text! + (sender.titleLabel?.text)!
    ICAOtextField.text = updateDicAOtextField
    
    if updateDicAOtextField.count >= 3 {
        let index = listArray.firsTindex { (list) -> Bool in
            if list.icao == updateDicAOtextField {
                return true
            }
            return false
        }
        if index != nil {
            callsigntextLabel.text = listArraY[index!].callsign
        }
        ICAOtextField.text = ""
    }
}
,
import UIKit

class ViewController: UIViewController,UITextFieldDelegate {

@IBOutlet var ICAOtextField: UITextField!
@IBOutlet var callsigntextLabel: UILabel!

var updateDicAOtextField = ""
var listArray = [list]()

override func viewDidLoad() {
    super.viewDidLoad()
    
    ICAOtextField.delegate = self
    ICAOtextField.addTarget(self,action: #SELEctor(textFieldDidChangE),for: UIControl.Event.ediTingChanged)
    
    setUpList()
}



@objc func textFieldDidChange(textField: UITextField) {
     if ICAOtextField.text!.count >= 3 {
         let index = listArray.firsTindex { (list) -> Bool in
            if "\(list.icao)" == ICAOtextField.text {
                 return true
             }
             return false
         }
         if index != nil {
            callsigntextLabel.text = listArraY[index!].callsign
         }
     }
}



private func setUpList() {

listArray.append(list(icao: "AAB",callsign: "A-B-G",image: "BELGIUM"))
listArray.append(list(icao: "AAC",callsign: "ARMYAIR",image: "UK"))
listArray.append(list(icao: "AAF",callsign: "AZUR",image: "FRANCE"))
listArray.append(list(icao: "AAL",callsign: "AMERICAN",image: "USA"))
}

@IBACtion func abcButton(_ sender: UIButton) {
    
    updateDicAOtextField = ICAOtextField.text! + sender.currenttitle!
    ICAOtextField.text = updateDicAOtextField
    
    if updateDicAOtextField.count > 3 {
        ICAOtextField.text = ""
    }
}

@IBACtion func clearButton(_ sender: UIButton) {
    ICAOtextField.text = ""
    callsigntextLabel.text = ""
}

}

班级列表{

let icao: String
let callsign: String
let image: String

init(icao: String,callsign: String,image: String) {
    
    self.icao = icao
    self.callsign = callsign
    self.image = image
}

}

@H_607_46@

大佬总结

以上是大佬教程为你收集整理的如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)全部内容,希望文章能够帮你解决如何使用数组的“if”语句设置搜索,非常基本的应用程序(swift)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。