[英]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.