I have made this:
var data = ["Apple", "Apricot", "Banana", "Blueberry", "Cantaloupe", "Cherry",
"Clementine", "Coconut", "Cranberry", "Fig", "Grape", "Grapefruit",
"Kiwi fruit", "Lemon", "Lime", "Lychee", "Mandarine", "Mango",
"Melon", "Nectarine", "Olive", "Orange", "Papaya", "Peach",
"Pear", "Pineapple", "Raspberry", "Strawberry"]
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 12
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return data.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellLabel", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
cell.textLabel?.text = data[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return months[section]
}
Now how do I choose what variables in my data array go into which "month" section? Is there a method I should use that I'm unaware of?
(This is in a class that extends UITableView)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int and tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell have section and indexPath arguments, indexPath has section variable. So basically you should do some switch statements in these functions to return desired data based on the month. It might be a better idea to have an array of data for each month. Or multidimensional array, or even some custom datatype.
Anyways, the code might be something like:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return dataJanuary.count
}
else if section == 1 {
return dataFebruary.count
}
// ...
return 0
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellLabel", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
if indexPath.section == 0 {
cell.textLabel?.text = dataJanuary[indexPath.row]
}
else if indexPath.section == 1 {
cell.textLabel?.text = dataFebruary[indexPath.row]
}
// ...
return cell
}
Related
So I have been studying Swift and trying to use a TableView with two sections. The thing is:
I have successfully developed an application using TableViewController with just one section and used data from a class called "Opcao" to populate the rows.
So I decided to create another section by setting return 2 on override func numberOfSections(in tableView: UITableView) -> Int and it worked, I only really needed two sections.
My problem: both of the sections are presenting the same number of rows and the same content on it. How could I change it? I mean, I would like the second section called "Teste" to have its own cell fields (different from the first section) but also populated with info of Opcao class.
The sections names on my TableView should be actually the attribute called "section", and the rows content should be the the number of rows in a cell is how many objects there are with which kind of "section". What should I do?
Opcao.swift:
class Opcao {
var nome:String
var descricao: String
var section: String
var segueIdentifier: String
init(nome: String, descricao: String, section: String, segueIdentifier: String){
self.nome = nome //displayed as main value of the cell
self.descricao = descricao //description which goes bellow the cell title
self.section = section // what I though it could be the section tittle which the option belongs to
self.segueIdentifier = segueIdentifier //used for other stuff, not relevant to this situation
}
Parts of TableViewController.swift:
class TableViewController: UITableViewController {
var opcoes: [Opcao] = []
var titulos: [String] = ["1a Habilitação", "Teste"]
override func viewDidLoad() {
super.viewDidLoad()
gerarOpcoes()
}
func gerarOpcoes(){
//criando opcao 1
var opcao1: Opcao
opcao1 = Opcao(nome: "Novo simulado", descricao: "Clique para começar um novo simulado.", section: "phab", segueIdentifier: "A")
self.opcoes.append(opcao1)
//criando opcao 2
var opcao2: Opcao
opcao2 = Opcao(nome: "Responder livremente", descricao: "Responda diversas perguntas sem tempo limite.", section: "phab", segueIdentifier: "B")
self.opcoes.append(opcao2)
//criando opcao 3
var opcao3: Opcao
opcao3 = Opcao(nome: "Histórico", descricao: "Veja seus últimos resultados.", section: "phab", segueIdentifier: "C")
self.opcoes.append(opcao3)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return opcoes.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "celula", for: indexPath)
cell.textLabel?.text = self.opcoes[indexPath.row].nome
cell.detailTextLabel?.text = self.opcoes[indexPath.row].descricao
return cell
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return titulos[section]
}
You can do it in a variety of ways. Easiest way would be having different arrays for different sections (Although it might not be the best approach). Then altering numberofRowsInSection depending on that too. Lets see:
Create another array:
var opcoesSecond: [Opcao] = []
Another deployment method for second array, this time lets put two objects only:
func gerarOpcoesForSecond(){
var opcao1: Opcao
opcao1 = Opcao(nome: "Novo simulado", descricao: "Clique para começar um novo simulado.", section: "phab", segueIdentifier: "A")
self.opcoesSecond.append(opcao1)
//criando opcao 2
var opcao2: Opcao
opcao2 = Opcao(nome: "Responder livremente", descricao: "Responda diversas perguntas sem tempo limite.", section: "phab", segueIdentifier: "B")
self.opcoesSecond.append(opcao2)
}
Call both array deployment methods in viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
gerarOpcoes()
gerarOpcoesForSecond()
}
Then in your numberofRowsInSection method:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return opcoes.count
} else {
return opcoesSecond.count
}
}
In your cellForRowAt method:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "celula", for: indexPath)
if indexPath.section == 0 {
cell.textLabel?.text = self.opcoes[indexPath.row].nome
cell.detailTextLabel?.text = self.opcoes[indexPath.row].descricao
} else {
cell.textLabel?.text = self.opcoesSecond[indexPath.row].nome
cell.detailTextLabel?.text = self.opcoesSecond[indexPath.row].descricao
}
return cell
}
Again as mentioned in the comments, two-dimensional array might be better to prevent code repetition like we have in cellForRowAt method.
But this should solve your problem.
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return opcoes.count
}
you should return count based on the section.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "celula", for: indexPath)
cell.textLabel?.text = self.opcoes[indexPath.row].nome
cell.detailTextLabel?.text = self.opcoes[indexPath.row].descricao
return cell
}
again, you should set cell based on the section.
Please help with the error I have
on this line:
cell.name.text = names[indexPath.row] //error array index out of range
This is my declaration:
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
var names = ["Anna","aanal"]
var petnames = ["Anu","aalu"]
#IBOutlet var tableView: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
cell.name.text = names[indexPath.row] //error array index out of range
cell.petname.text = petnames[indexPath.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Your array only has 2 elements while your numberOfRowsInSection method returns 3. Either change it to 2 or add 3 elements in your array
The ideal way is to change
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
But usually dont work with 2 arrays and create a Entity object having name and petname as elements and then have an array of your entity class to populate tableview
Try this :
I think your are passed petnames in numberOfRowsInSection and names and petnames count are also different so this problem occurs .
Solution
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if names.count == petnames.count{
return petnames.count
}
return 0;
}
OR
You have passed more numberOfRowsInSection then array.count
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2 or names.count
}
There are 2 values in your arrays names and petnames. However, there are 3 rows in your Table View. So, if the 3rd row of the table view is selected, it will be out of range of the array as there is no 3rd element in the arrays.
The solution is to make your names array and petnames array contain 3 elements:
var names = ["Anna","aanal", "boo"]
var petnames = ["Anu","aalu", "bo"]
or to return 2 rows in your table view:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
The best way is to return the count of the arrays (if the count of both arrays are different, return nothing):
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if names.count == petnames.count {
return names.count
}
return 0
}
Just pass the count of array
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return yourArray.count
}
var names = ["Anna","aanal"] // you have 2 elemnts
var petnames = ["Anu","aalu"]
#IBOutlet var tableView: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//return 3 // you have returned 3 but it should be 2
// it should be
return 2
//or
// return names.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
cell.name.text = names[indexPath.row] //you got error because you are trying to get 3 element from array where as there are only 2 elements
cell.petname.text = petnames[indexPath.row]
return cell
}
It is better if you use your arrayname.count
I have a tableView on mainStoryboard with two custom cells.
I would like to set two more cells at different row.
However When I implemented the code the added cells replaces original cells. (Custom cell of "Basic grammar3" and "Basic grammar5" are disappearing.)
I was trying to find the answer but could not find out.
I have image and code added below.
import UIKit
class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet var tblStoryList: UITableView!
var array = PLIST.shared.mainArray
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.array.count + 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 || indexPath.row == 3 || indexPath.row == 5 {
let cell = tableView.dequeueReusableCell(withIdentifier: "HeaderCell", for: indexPath) as! HeaderCell
cell.headerTitle.text = indexPath.row == 0 ? "First Stage" : indexPath.row == 3 ? "Second Stage" : "Third Stage"
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryTableviewCell", for: indexPath) as! StoryTableviewCell
//making plist file
let dict = self.array[indexPath.row - 1]
let title = dict["title"] as! String
let imageName = dict["image"] as! String
let temp = dict["phrases"] as! [String:Any]
let arr = temp["array"] as! [[String:Any]]
let detail = "progress \(arr.count)/\(arr.count)"
//property to plist file をつなぐ
cell.imgIcon.image = UIImage.init(named: imageName)
cell.lblTitle.text = title
cell.lblSubtitle.text = detail
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
return
}
tableView.deselectRow(at: indexPath as IndexPath, animated:true)
if indexPath.row == 3 {
return
}
tableView.deselectRow(at: indexPath as IndexPath, animated:true)
if indexPath.row == 5 {
return
}
tableView.deselectRow(at: indexPath as IndexPath, animated:true)
let messagesVc = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
messagesVc.object = self.array[indexPath.row - 1]
self.navigationController?.show(messagesVc, sender: self)
}
You could use sections for your table view. Now, you are returning 1 in your numberOfSections function. And it is creating only one section. If you want to use headers, you can use sections for your need. And also you can fill your table view cells with multidimendional arrays. For example:
For adjusting your section headers:
let lessonTitles = ["First Stage", "Second Stage"]
Titles for sections:
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section < lessonTitles.count {
return lessonTitles [section]
}
return nil
}
For adjusting your sections and rows:
let lessons = [["Basic Grammar 1", "Basic Grammar 2"], ["Basic Grammar 3", "Basic Grammar 4"]]
Number of sections function should be:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return lessons.count
}
Number of rows in section should be:
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lessons[section].count
}
And creating your cells is like this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellText = data[indexPath.section][indexPath.row]
...
}
Try like this...
func numberOfSections(in tableView: UITableView) -> Int
{
return numberOfStages
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return numberOfRowsInCurrentStage
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
return customizedCell
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
return requiredHeight
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
{
return stageCountView
}
You can use viewForHeaderInSection if you want to show stage count on top.
edit: The comment by raki is the much better solution (use headers). I leave this here in case you want something closer to your existing implementation.
You have to change your numbering scheme in order to insert these additional rows (and not replace existing rows). So you might want to adjust the row for the "normal" elements like this:
func adjustRow(_ row: Int) -> Int {
if row < 3 {
return row
} else if row < 5 {
return row+1
} else {
return row+2
}
}
Lets consider this example:
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var tableView: UITableView!
var names = ["Vegetables": ["Tomato", "Potato", "Lettuce"], "Fruits": ["Apple", "Banana"]]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"test")
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return ???
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
return names.count
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]!{
return ???
}
func tableView(tableView: UITableView,
titleForHeaderInSection section: Int) -> String?{
return ????
}
}
let's assume that we need that the keys (fruits and vegetables) of the dictionary are the number of sections, plus they will be the titles of the sections. The items of the keys (eg apples and banana) will be the rows of each section. How can I implement this in my code? I know it might be easy but I couldn't figure it out my self.
You can use struct for that and here is example:
import UIKit
class TableViewController: UITableViewController {
var names = ["Vegetables": ["Tomato", "Potato", "Lettuce"], "Fruits": ["Apple", "Banana"]]
struct Objects {
var sectionName : String!
var sectionObjects : [String]!
}
var objectArray = [Objects]()
override func viewDidLoad() {
super.viewDidLoad()
for (key, value) in names {
println("\(key) -> \(value)")
objectArray.append(Objects(sectionName: key, sectionObjects: value))
}
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return objectArray.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return objectArray[section].sectionObjects.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
cell.textLabel?.text = objectArray[indexPath.section].sectionObjects[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return objectArray[section].sectionName
}
}
Swift 2
you dictionary example
var dic:Dictionary<String,String> = ["key":"value","key1":"value2"]
Your table
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
var key = Array(self.dic.keys)[indexPath.row]
var value = Array(self.dic.values)[indexPath.row]
cell.text = key + value
}
If you want it sorted use the global sorted function to sort the dictionary.
import UIKit
class TableViewController: UITableViewController {
var names = ["Vegetables": ["Tomato", "Potato", "Lettuce"], "Fruits": ["Apple", "Banana"]]
var namesSorted = [String, Array<String>]()
override func viewDidLoad() {
super.viewDidLoad()
// Sort names
namesSorted = sorted(names) { $0.0 < $1.0} // namesSorted = ["Fruits": ["Apple", "Banana"], "Vegetables": ["Tomato", "Potato", "Lettuce"]]
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return namesSorted.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return namesSorted[section].1.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
cell.textLabel?.text = namesSorted[indexPath.section].1[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return namesSorted[section].0
}
}
All collection types must be Array
var names = [["Tomato", "Potato", "Lettuce"], ["Apple", "Banana"]]
var sectionNames = ["Vegetables", "Fruits"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return names[section].count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{
return names.count
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]!{
return sectionNames
}
func tableView(tableView: UITableView,
titleForHeaderInSection section: Int) -> String?{
return sectionNames[section]
}
From Apple Documentation :
var keys: LazyForwardCollection<MapCollectionView<Dictionary<Key, Value>, Key>> { get }
Description: A collection containing just the keys of self. Keys appear in the same order as they occur as the .0 member of key-value pairs in self. Each key in the result has a unique value.
names.keys.array returns an Array of the keys.
SO:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return names.keys.array[section].count
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]!{
return names.keys.array
}
func tableView(tableView: UITableView,
titleForHeaderInSection section: Int) -> String?{
return names.keys.array[section]
}
This will work on Any Dictionary with any amount of data(even if it is unknown to the programmer
An easier way to solve this problem is to copy your dictionary into a temporary variable. Use removeFirst to extract the values from the array inside the dictionary.
var itemList=["Grocery":["soap","flour","carrots"],"Vehicles":["oil change","gas","tire rotation"],"Household":["Cable","Tv","cellphone"]]
var itemListTmp :[String:[String]] = [:]
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text=itemListTmp[keysItem[indexPath.section]]?.removeFirst()
//cell.textLabel?.text=itemList[indexPath.section].items[indexPath.row]
return cell
}
Another way of solving this problem is to extract keys and values in separate arrays:
var task=[String](itemList.keys)
var tobeDone=[[String]](itemList.values)
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return task[section]
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text=tobeDone[indexPath.section][indexPath.row]
return cell
}
Similar to https://stackoverflow.com/a/31136537/11098567 answer I would use classes instead of structs, so that you can manipulate or add to your values after it has been placed into the array.
#objc func addToInitialClassInstance() {
let classInstance = Class(property1: String, property2: [CLass2.init(property1: String, property2: String)])
let isAvailable = initialClassInstance.contains { (classInArray) -> Bool in
if classInArray.property == classInstance.property {
classInArray.property2.append(classInstance.property2[0])
return true
}
return false
}
if !isAvailable {
initialClassInstance.append(classInstance)
}
tableView.reloadData()
}
Lets say that I have three arrays in my ViewController. Two of them represent section cells and one represents the sections.
How do I append a TableViewCell to a specific Section?
ViewController.swift:
// represents my 2 sections
var sectionNames = ["Switches","Settings"]
// data for each section
var switchData = ["switch1","switch2", "switch3"]
var settingData = ["setting1", "setting2"]
A better approach would be to use a dictionary instead of separate arrays:
let data: Dictionary<String,[String]> = [
"Switches": ["switch1","switch2","switch3"],
"Settings": ["setting1","setting2"]
]
Here the dictionary keys are the sections and the values arrays are the data for each section.
So, a tableViewController might look like this:
class MyTableViewController: UITableViewController {
let data: Dictionary<String,[String]> = [
"switches": ["switch1","switch2","switch3"],
"settings": ["setting1","setting2"]
]
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// Return the number of sections.
return data.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
let sectionString = Array(data.keys)[section]
return data[sectionString]!.count
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let sectionString = Array(data.keys)[section]
return sectionString
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
let sectionString = Array(data.keys)[indexPath.section]
cell.textLabel?.text = data[sectionString]![indexPath.row]
return cell
}
}
Result: