vendredi 20 janvier 2017

Randomizing table view cells

I am trying to simply make a quick little app in XCode that will allow me to enter a name and it will create a cell in a section. I also have a "Randomize" UIButton to randomize the names into groups of 2, so one section is "Group 1, the next is "Group 2" and so on, with just 2 cells. I am completely stuck and new to Swift entirely.

I have a Model Controller set up with just an addName function and an array of said "pairs". I already have an alert that allows me to enter that name. I'm guessing I need a numberOfSections?

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return PairController.sharedController.pairs.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "groupCell", for: indexPath)
    let pair = PairController.sharedController.pairs[indexPath.row]
    cell.textLabel?.text = pair.name

    return cell
}

@IBAction func randomizeButtonTapped(_ sender: Any) {

}




Aucun commentaire:

Enregistrer un commentaire