gpt4 book ai didi

swift - 使用 pickerView 发送到实例的无法识别的选择器

转载 作者:行者123 更新时间:2023-11-30 11:03:35 25 4
gpt4 key购买 nike

2018-10-25 18:19:37.940317-0700 AddressBookApp[3976:92391] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.2018-10-25 18:19:47.916807-0700 AddressBookApp[3976:92391] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/broque/Library/Developer/CoreSimulator/Devices/A4672181-9DB1-4F6B-8251-1EFB52A087A5/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles2018-10-25 18:19:47.918140-0700 AddressBookApp[3976:92391] [MC] Reading from private effective user settings.2018-10-25 18:20:01.956143-0700 AddressBookApp[3976:92391] -[AddressBookApp.SecondViewController numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7f9007409f602018-10-25 18:20:01.971135-0700 AddressBookApp[3976:92391] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AddressBookApp.SecondViewController numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7f9007409f60'
import UIKit

class SecondViewController: UIViewController {
@IBOutlet weak var name: UILabel!
@IBOutlet weak var number: UILabel!
@IBOutlet weak var email: UILabel!

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return (FirstViewController.model.sendArray(index: row-1)?.lastName)! + ", " + (FirstViewController.model.sendArray(index: row-1)?.firstName)!
}

// called when a selection is made
// recall that the first row is row 0
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
name.text = (FirstViewController.model.sendArray(index: row-1)?.firstName)! + ", " + (FirstViewController.model.sendArray(index: row-1)?.lastName)!
number.text = FirstViewController.model.sendArray(index: row-1)?.number
email.text = FirstViewController.model.sendArray(index: row-1)?.email
}

func numberOfComponents(_ pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent
component: Int) -> Int {
return 5 // this should be declared as a constant!
}
}

最佳答案

不要自己完全输入方法签名。让 Xcode 为您完成。

应该是:

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

您还应该指出您的 View Controller 符合选择器 View 协议(protocol):

class SecondViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {

关于swift - 使用 pickerView 发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53000167/

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