簡體   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