• <bdo id='mCVK2'></bdo><ul id='mCVK2'></ul>

  • <legend id='mCVK2'><style id='mCVK2'><dir id='mCVK2'><q id='mCVK2'></q></dir></style></legend>
    <i id='mCVK2'><tr id='mCVK2'><dt id='mCVK2'><q id='mCVK2'><span id='mCVK2'><b id='mCVK2'><form id='mCVK2'><ins id='mCVK2'></ins><ul id='mCVK2'></ul><sub id='mCVK2'></sub></form><legend id='mCVK2'></legend><bdo id='mCVK2'><pre id='mCVK2'><center id='mCVK2'></center></pre></bdo></b><th id='mCVK2'></th></span></q></dt></tr></i><div id='mCVK2'><tfoot id='mCVK2'></tfoot><dl id='mCVK2'><fieldset id='mCVK2'></fieldset></dl></div>
    <tfoot id='mCVK2'></tfoot>

      1. <small id='mCVK2'></small><noframes id='mCVK2'>

        快速使用带有多个组件的 UIPickerView

        Using UIPickerView with multiple components in swift(快速使用带有多个组件的 UIPickerView)
            <legend id='KyBnB'><style id='KyBnB'><dir id='KyBnB'><q id='KyBnB'></q></dir></style></legend>
              <tbody id='KyBnB'></tbody>

            <small id='KyBnB'></small><noframes id='KyBnB'>

                <bdo id='KyBnB'></bdo><ul id='KyBnB'></ul>

                  <i id='KyBnB'><tr id='KyBnB'><dt id='KyBnB'><q id='KyBnB'><span id='KyBnB'><b id='KyBnB'><form id='KyBnB'><ins id='KyBnB'></ins><ul id='KyBnB'></ul><sub id='KyBnB'></sub></form><legend id='KyBnB'></legend><bdo id='KyBnB'><pre id='KyBnB'><center id='KyBnB'></center></pre></bdo></b><th id='KyBnB'></th></span></q></dt></tr></i><div id='KyBnB'><tfoot id='KyBnB'></tfoot><dl id='KyBnB'><fieldset id='KyBnB'></fieldset></dl></div>

                1. <tfoot id='KyBnB'></tfoot>
                  本文介绍了快速使用带有多个组件的 UIPickerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直试图让这个工作多年没有成功,如果这对你们来说似乎很容易,请道歉.

                  Hi there I have been trying to get this working for ages with no success so apologies if this seems easy for you guys.

                  我想使用 3 轮 UIPickerView - 第一个轮的 didSelectRow 值将用于更改其余两个轮的数组,但它们将与转换应用程序相同.

                  I want to use a 3 wheel UIPickerView - The 1st wheel didSelectRow value will be used to change the array for the remaining two wheels but they will be the same as it is a conversion app.

                  当填充轮子说 Anyobject 与 String 不同时,这似乎给我一个错误.我看不出有什么问题,但我知道这是我错过的基本内容.

                  It seems to throw me an error up when populating the wheels saying that Anyobject is not identical to String. I cannot see anything wrong but I know it is something basic I have missed.

                  任何指针将不胜感激.

                  莫蒂.

                  //  ViewController.swift
                  //  picker test
                  
                  import UIKit
                  
                  class ViewController: UIViewController, UIPickerViewDelegate {
                  
                      @IBOutlet weak var picker1Label: UILabel!
                      @IBOutlet weak var picker2Label: UILabel!
                  
                      @IBOutlet weak var bigPicker: UIPickerView!
                  
                      var wheelContents = []
                      var length = ["metres","feet","yards","inches","mm","cm","miles"]
                      var volume = ["m3","US Gall","Imp Gall","Barrels", "cubic FT","litres"]
                      var conType = ["length","volume"]
                  
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          // Do any additional setup after loading the view, typically from a nib.
                          wheelContents = [conType,length,length]
                  
                      }
                  
                      override func didReceiveMemoryWarning() {
                          super.didReceiveMemoryWarning()
                          // Dispose of any resources that can be recreated.
                      }
                  
                  
                      //For main selection of type of conversion
                      // returns the number of 'columns' to display.
                      func numberOfComponentsInPickerView(bigPicker: UIPickerView) -> Int{
                  
                          return wheelContents.count
                  
                      }
                  
                      // returns the # of rows in each component..
                      func pickerView(bigPicker: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
                  
                          return wheelContents[component].count
                  
                  
                      }
                  
                      func pickerView(bigPicker: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!{
                  
                          return wheelContents[component][row]
                  
                      }
                  }
                  

                  推荐答案

                  由于你声明了这样的wheelContents wheelContents = [],没有指定它的元素类型,编译器自动推断它是数组AnyObjects 又名 [AnyObject].

                  Since you declared wheelContents like this wheelContents = [], without specifying its elements type, the compiler automatically infers that it is array of AnyObjects aka [AnyObject].

                  这就是为什么当您返回 wheelContents[component].count 时它会生成错误:此时编译器需要一个 String! 但您正在提供AnyObject.

                  That's the reason why when you are returning wheelContents[component].count it generates an error: at that moment the compiler is expecting a String! but you are providing an AnyObject.

                  这是一个非常容易解决的问题,您应该在声明它时指定数组的内容.(它是一个字符串数组,又名 [[String]])

                  It's a really easy fix, you should just specify what the content of the array it is going to be when you declare it. (it's an array of arrays of strings aka [[String]])

                  这篇关于快速使用带有多个组件的 UIPickerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)
                  • <legend id='ykpQa'><style id='ykpQa'><dir id='ykpQa'><q id='ykpQa'></q></dir></style></legend>
                    <i id='ykpQa'><tr id='ykpQa'><dt id='ykpQa'><q id='ykpQa'><span id='ykpQa'><b id='ykpQa'><form id='ykpQa'><ins id='ykpQa'></ins><ul id='ykpQa'></ul><sub id='ykpQa'></sub></form><legend id='ykpQa'></legend><bdo id='ykpQa'><pre id='ykpQa'><center id='ykpQa'></center></pre></bdo></b><th id='ykpQa'></th></span></q></dt></tr></i><div id='ykpQa'><tfoot id='ykpQa'></tfoot><dl id='ykpQa'><fieldset id='ykpQa'></fieldset></dl></div>

                    <small id='ykpQa'></small><noframes id='ykpQa'>

                    <tfoot id='ykpQa'></tfoot>
                        <bdo id='ykpQa'></bdo><ul id='ykpQa'></ul>
                          <tbody id='ykpQa'></tbody>