繁体   English   中英

类型'Int'不符合协议'BooleanType'

[英]Type 'Int' does not conform to protocol 'BooleanType'

我对这个陈述做错了什么? currentRow是一个NSIndexPath

  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row && currentRow?.row == 5 {
        return  300
    }
    return 70

我得到的错误是:

类型'Int'不符合协议'BooleanType'

如果要检查,如果currentRow和indexPath都是5 ,则不能使用if语句。 将其更改为:

 if indexPath.row == currentRow?.row  && currentRow == 5 {

要么:

 if indexPath.row == 5  && currentRow?.row == 5 {

如果要检查indexPath是否为nil请检查indexPath是否为0

if indexPath.row != 0 && currentRow?.row == 5 {

发生这种情况是因为您正在尝试检查非可选的indexPath.row是否已设置。

如果您想检查indexPath.row为零,请添加一个显式检查:

if indexPath.row != 0 && currentRow?.row == 5 {
    return  300
}

与Objective-C不同,它允许您在没有显式条件的情况下进行nil和零检查,Swift期望显式条件,或使用由可选类型实现的BooleanType协议执行检查。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM