在cellForRowAtIndexPath
我:只有「如果讓」的其他塊?
if let imageView = cell.viewWithTag(SOME_TAG) as? UIImageView
{
// Nothing to do here.
}
else
{
// Add image view to cell.
}
,但我只需要else
塊。有沒有辦法反轉if let xyz =
?
(我知道我可以打破它,有一個if imageView == nil
)
這可能會有所幫助:http://stackoverflow.com/a/27412931/1208191 –
另一個很好的建議是避免標籤儘可能。他們確實污染了源代碼。 – Sulthan
@Sulthan同意,但增加了對可重複使用的表格視圖單元的追加子視圖的最小污染。 –