2016-04-12 54 views
0

我期待创建一个类似于这个的空数据集。不是它的外观或任何东西,只是得到一个空数据集的一般概念。我不确定如何做到这一点,我一直想将这个植入到我的应用程序中,而不使用任何cocoapods。这很容易做到吗? 我对Swift相当陌生,所以我一直无法弄清楚这一点。我尝试了下面的代码,但有很多错误,我意识到这是没有意义的。Swift空数据集

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
if return == 0 { 
     // Create the empty data set 
    } else { 
     return jsonfile["response"]["data"].count 
    } 
} 

enter image description here

回答

2

你已经显示的一个和其他许多人使用

https://github.com/dzenbot/DZNEmptyDataSet

而且在你的榜样将是

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    let count = jsonfile["response"]["data"].count 
    if count == 0 { 
     return 1 
    } 
    return count 

}

然后在你的cellForRow:返回一个没有数据单元。

编辑:

internal func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let count = jsonfile["response"]["data"].count 
     if count == 0 { 
      return noDataCell 
     } else { 
      return normalCell 
     } 
    } 
+0

那么我会返回,如果它是在cellForRow 0?如果编辑的结果大于 –

+0

,我已经在那里返回结果。用通常的单元格构建或者返回单元格的方法替换简单的单元格名称。 – SeanLintern88