我有一個segmentedControl
和一個tableView
下面。當點擊段時停止cellForRowAtIndexPath
SegmentedControl
有兩個部分:'新聞'和'事件'。
新聞和活動下載到var news = [News]()
在func getJson(type: Int)
。
新聞 - news.type = 1
,事件news.type = 2
。
我getJson
方法是:
func getJson(type: Int) {
self.news = [] // empty news array
if jsonData["type"] == type {
// save needed news to array
self.news.append(News(id: jid, title: jtitle, subtitle: jsubtitle, urlstring: jurlstring, image: jimage!))
}
}
所以,問題是,當我滾動,及時挖掘第二部分,應用程序崩潰:
因爲self.news = []
和self.news.append
在getJson
之間,在這裏去cellForRowAtIndexPath
。
我的問題是如何當我點擊段時停止cellForRowAtIndexPath
?謝謝。
你在'numberOfRowsInSection'中返回什麼?你在切換段並開始加載數據時調用'reloadData'嗎? – Paulw11
我返回'news.count'。我打電話。問題是'tableView'不斷填充單元格,但'getjson'確實'self.news = []' – aaisataev
通常情況下,您會將數據加載到臨時數組中,然後在加載數據後將數據複製到'self.news'中,然後調用reloadData – Paulw11