热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从Swift中的IBOutletCollection获取项目-GettingAnItemfromIBOutletCollectioninSwift

ImgettinganerrorasTypeofexpressionisambiguouswithoutmorecontext我收到一个错误,因为“没有更多上下文,表达

I'm getting an error as "Type of expression is ambiguous without more context"

我收到一个错误,因为“没有更多上下文,表达的类型是模糊的”

Here is my code

这是我的代码

@IBOutlet var customerDashboardButtons:[NSArray]?

var predicate = NSPredicate(format: "SELF.tag == %d", tag)
var filteredButtOns= customerDashboardButtons!.filter { predicate.evaluateWithObject($0) };
if 0 

I have tried the following,

我试过以下,

var button:UIButton = customerDashboardButtons!.first //Error "NSArray? is not convertible to UIButton"

var button = customerDashboardButtons!.first as UIButton //Error "NSArray? is not convertible to UIButton"

Any help on this is appreciated.

对此有任何帮助表示赞赏。

2 个解决方案

#1


7  

@IBOutlet var customerDashboardButtons:[NSArray]?

Creates an array of arrays.
Calling customerDashboardButtons!.first will return the first array (the NSArray) in your array (the […] will also create an array)

创建一个数组数组。调用customerDashboardButtons!.first将返回数组中的第一个数组(NSArray)([...]也会创建一个数组)

I suspect you want your customerDashboardButtons to be an array of UIButton’s so you would use

我怀疑你希望你的customerDashboardButtons是一个UIButton的数组,所以你会使用

@IBOutlet var customerDashboardButtons:[UIButton]?

Using customerDashboardButtons!.first here will give you a UIButton. Since the type of the array is UIButton, you don’t have to declare your button as UIButton.

使用customerDashboardButtons!.first here将为您提供UIButton。由于数组的类型是UIButton,因此您不必将按钮声明为UIButton。

  var button = customerDashboardButtons!.first

Will work if you change your array.

如果你改变阵列将会工作。

#2


0  

Here is an example how to create IBOutletCollection and get an Item from it

以下是如何创建IBOutletCollection并从中获取项目的示例

1) @IBOutlet var simpleTextField: [UITextField]!

1)@IBOutlet var simpleTextField:[UITextField]!

2) Example to get textFiled from that.

2)从中获取textFiled的示例。

for index in 0...(simpleTextField.count - 1)  {
    let textField : UITextField = simpleTextField[index]
    textField.isUserInteractiOnEnabled= true
}

推荐阅读
author-avatar
楼下地小黑
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有