2017-10-17 77 views
1

我工作的UI,使其相同的設計,我以前heightForRowAt,使第一部分的單元格的高度96PX,我試過:的UITableView heightForRowAt老是死機

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     switch indexPath.section { 
     case 0: 
      return 96.0 
     default: 
      return 56.0 
     } 
} 

但它死機了,我搜索到處但問題一直沒有得到解決

所以我嘗試來進行測試:

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     return 56.0 
} 

而且它還墜毀。

Xcode只是給我Thread 1:signal SIGABRT錯誤,我找不到解決方案。爲什麼這發生在我身上?

+++控制檯消息當錯誤發生

screenshot of console message

+0

您是否嘗試一步一步地查看它何時崩潰? –

+0

是的,我檢查了所有的功能,它只與它墜毀 –

+0

你確定你的數據源數組是否有正確的映射? –

回答

1

你的錯誤與你提到的自定義高度無關。在你的方法來獲得在指數路徑行的單元格您要離隊兩個單元的同一指標的路徑...

你必須在你的代碼是這樣的......

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "ident", for: indexPath) 
    let cell2 = tableView.dequeueReusableCell(withIdentifier: "ident", for: indexPath) 
} 

而且iOS正在崩潰,讓您知道您只能爲每個索引路徑出列一個單元格...

+0

謝謝!終於我知道了 –

+1

,他明白了:') –

-2

@Cyan利,只是檢查鏈接我共享,檢查接受的答案,你skiped委派:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { 
     var cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell 

     if (cell == nil) { 
      cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell") 
     } 

     cell.textLabel.text = "TEXT" 
     cell.detailTextLabel.text = "DETAIL TEXT" 

     return cell 
    } 
+2

應該是註釋。 –

+0

我已經做了@puneet,第一個tym被轉換爲註釋,但第二個tym它出現了答案,不是我的錯 –