将多个UITextField附加到一个iBOutlet

问题描述 投票:0回答:2

我想将多个UITextField链接到一个iBOutlet。我尝试过以下链接Multiple IBOutlets in same line of same type in Swift的建议

但这不起作用,因为我得到以下错误。

'weak' may only be applied to class and class-bound protocol types, not 
'Array<UITextField>'

 @IBOutlet weak var driverTextField: Array<UITextField>=[]

Simulator and code side by side.

基本上,我想将模拟器中的最后3个UITextfield连接到driverTextfield。

uitextfield swift4 ios-simulator
2个回答
1
投票

你有:

@IBOutlet weak var driverTextField: Array<UITextField>=[]

编译器正确地抱怨你不能用数组说weak。但是你需要一个阵列来制作插座系列。所以只需删除weak就可以了。

基本上,我想将模拟器中的最后3个UITextfield连接到driverTextfield

是的,一旦你删除weak,你的代码将编译,你将能够在Interface Builder(故事板)中配置它。


0
投票

你可以做一个“插座收藏”。并使用和for循环和索引访问每个出口。 @IBOutlet var driverTextField: [UITextField]!

Select outlet collection from dropdown

从下拉列表中选择插座集合,然后将所有文本字段的出口拖放到此插座。

© www.soinside.com 2019 - 2024. All rights reserved.