I am creating an iOS Pokémon database application using Swift, for my A2 computing coursework. Before this project, I have not used Swift, so I am teaching myself using relevant examples which I can hopefully copy and paste from.
I am using Xcode 6.1.1 and the SQLite.swift library from Stephen Celis.
One such test is producing a UITableView which can read from my pre-existing, pre-populated database.
I've managed to get the UITableView to create all the cells - and set the detailTextLabel to the indexPath (plus 1, so it starts at 1 and ends at 721 instead of starting at 0 and ending at 720). So I have 721 cells in the table just fine.
However, I can't seem to get the textLabel for each cell to display the correct data. Instead, it displays "SQLite.Expression" for each cell.
Above the ViewController class in the ViewController.swift file, I have
let db = Database("/Users/rhysmorgan/Documents/Coding/DatabaseLoadTest/Pokémon Database.sqlite", readonly: true)
let pokemonTable = db["Pokémon"]
let name = Expression<String>("PokéName")
let gen = Expression<Int>("Generation")
and in the main tableView function, I have
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let rowno: Int = indexPath.row + 1
let formatter = NSNumberFormatter(); formatter.minimumIntegerDigits = 3
let formattedrowno = formatter.stringFromNumber(rowno)
let pokemonname = pokemonTable[name]
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = "\(pokemonname)"
cell.detailTextLabel?.text = "\(formattedrowno!)"
return cell
}
Is anybody able to help me? With thanks in advance!
Aucun commentaire:
Enregistrer un commentaire