我有两个数组Data1和Data2,我想将这些数据(它们包含字符串)中的数据填充到两个不同部分的表视图中。
第一部分应该有一个标题“Some Data 1”,第二部分应该标题为“KickAss”。 @H_404_2@我有两个部分填充第一个数组的数据(但也没有标题)。 @H_404_2@这是我的代码到目前为止
谢谢
第一部分应该有一个标题“Some Data 1”,第二部分应该标题为“KickAss”。 @H_404_2@我有两个部分填充第一个数组的数据(但也没有标题)。 @H_404_2@这是我的代码到目前为止
@H_404_2@在cellForRowAtIndexPath方法中,是否可以识别这个部分,就像我在numberOfRowsInSection方法中所做的那样?另外,如何给每个部分的标题?
- override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return 2
- }
- override func tableView(tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
- var rowCount = 0
- if section == 0 {
- rowCount = Data1.count
- }
- if section == 1 {
- rowCount = Data2.count
- }
- return rowCount
- }
- override func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath) as UITableViewCell
- let ip = indexPath
- cell.textLabel?.text = Data1[ip.row] as String
- return cell
- }
谢谢