2017-08-06 54 views
0

我正在嘗試在我的willDisplay cell:UITableViewCell方法中複製自動UITableViewCell分隔符插入。插頁我的應用程序的分離取決於Bool條件,就像這樣:自動UITableView分隔符插入

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 

    let profileCell = cell as! ProfileCell 
    profileCell.separatorInset = isProfileComplete ? UIEdgeInsets.zero : UIEdgeInsets(0, 15, 0, 0) 

} 
我目前使用 UIEdgeInsets(0, 15, 0, 0)複製「自動」 UITableViewCell分離器插圖

,但這是不夠的所有設備。我希望有類似UIEdgeInsets.automatic的東西,但這只是而不是存在。有任何想法嗎?

+2

@MacLeod您可以使用視圖創建自己的自定義分隔符,並應用適當的約束條件。 –

+0

爲什麼不添加自定義視圖並配置其外觀? –

+0

@TusharSharma我明白一個自定義視圖是可能的,但是有什麼方法可以使用默認的分隔視圖來完成此操作嗎? –

回答

0

似乎沒有直接的方法來實現我正在尋找使用內置的UITableViewCell分隔符。根據您的建議,最好的解決方法是存儲defaultInset值,並在必要時重新使用它。

var automaticInset = UIEdgeInsets.zero 

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 

    let profileCell = cell as! ProfileCell 
    automaticInset = profileCell.separatorInset 
    profileCell.separatorInset = isProfileComplete ? UIEdgeInsets.zero : automaticInsets 

}