2017-05-06 25 views
-1

我怎麼能忽略數組的第一個項目時,在TableView中顯示?忽略數組中第一項的UITableView - 斯威夫特

我要的是忽略的第一個項目時,在一個UITableView呈現,我不想刪除它只是不TableView中表現出來。

下面的代碼示出了從在TableView中所述陣列的所有項目。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return lists.count 
} 


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "listCell", for: indexPath) 

    let data = lists[indexPath.row] 
    cell.textLabel!.text = data.listName 
    return cell 
} 
+1

你沒有足夠的展示代碼。顯示'numberOfRowsInSection'。 – matt

+0

更新後。謝謝。 –

+1

爲什麼不擁有主表以及表視圖數據源實際使用的數據模型? – rmaddy

回答

1

您的數據源的方法是使用lists作爲基礎,而你不想做任何的混亂,向上。 numberOfRowsInSectioncellForRowAt需要保持同步。

我能想到的兩種可能性:

  • 保持真正模式在其他地方,並保持在lists要在表中包括模型的唯一部分。

  • 或(一個完全不同的方法)實施heightForRowAt給不需要的行零高度。

+0

我明白了,我會和你的第一個建議一起去。 –

+1

好,因爲那就是我會做的。 :) – matt

+0

非常感謝您的幫助! –