UITableView cells not updating in Swift

mattgabor

I'm trying to set the text of a cell in a UITableView inside of a UIViewController and the text is not being updated. Also, nothing gets printed even though I have two print statements, so it seems like the functions are not being called. Here is my code:

class HomePageViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate {
@IBOutlet weak var flaggedTable: UITableView!
@IBOutlet weak var recentTable: UITableView!

var flaggedSerials = [DataCell]()
var recentlyViewedSerials = [DataCell]()

override func viewDidLoad() {
    super.viewDidLoad()

    addSerial("FCGPR0TUG07P", status: "Shipped", issues: 6, reworks: 2, index: 0, flagged: false)    
}    

func addSerial(serial: String, status: String, issues: Int, reworks: Int, index: Int, flagged: Bool)
{
    var currentSerial = DataCell()

    currentSerial.serial = serial
    currentSerial.status = status
    currentSerial.issues = "\(issues) Reported Issues"
    currentSerial.reworks = "\(reworks) Reported Reworks"
    currentSerial.index = index

    if flagged == true {
        flaggedSerials.append(currentSerial)
    }
    else {
        recentlyViewedSerials.append(currentSerial)
    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        println(recentlyViewedSerials.count) // This line does not get printed
        return recentlyViewedSerials.count
    }

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("FlaggedCell", forIndexPath: indexPath) as! UITableViewCell
    addSerial("FCGPR0TUG07P", status: "Shipped", issues: 6, reworks: 2, index: 0, flagged: false)
    println(recentlyViewedSerials[indexPath.row].serial) // This line does not get printed
    cell.textLabel?.text = recentlyViewedSerials[indexPath.row].serial

    return cell
    }
}
asifmohd

Replace the class definition line with this line:

class HomePageViewController: UIViewController, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource {

Also remember to set the delegate and datasource properties of the tableView to self.

You can do this using interface builder or using code in the viewDidLoad method:

override func viewDidLoad() {
super.viewDidLoad()

// do this for all your tableViews and make sure to have an outlet configured first
tableView.delegate = self
tableView.datasource = self
addSerial("FCGPR0TUG07P", status: "Shipped", issues: 6, reworks: 2, index: 0, flagged: false)    
}   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Swift - Reorder UITableView cells

From Dev

Swift : Clear UITableView Cells

From Dev

Swift - Fading cells in UITableView

From Dev

UITableView in Swift - dequeueing of cells

From Dev

Switching Custom Cells in UITableView in swift

From Dev

Cells not appearing in UITableView - Swift 3

From Dev

Updating Tableview Cells with a Button in swift

From Dev

Swift updating UITableView with new data

From Dev

Swift UITableView visually deselects cells on scroll

From Java

UITableview with more than One Custom Cells with Swift

From Dev

Fail to hide empty cells in UITableView Swift

From Dev

getting data from each UITableView Cells Swift

From Dev

UITableView does not display the cells (using swift )

From Dev

How to hide specific cells in a static UItableview, in swift?

From Dev

UIImage not appearing in prototype cells in UITableView (Swift)

From Dev

How to hide specific cells in a static UItableview, in swift?

From Dev

Updating a UITableView in Swift from another ViewController

From Dev

Updating a UITableView in Swift from another ViewController

From Dev

Updating UITableView in another UIViewController without a segue in Swift

From Dev

UITableView not updating

From Dev

How to prevent UITableView from reuse custom cells Swift

From Dev

Swift 2.0, UITableView: cellForRowAtIndexPath returning nil for non-visible cells

From Dev

Swift - Segue from static UITableView with selected cells text (prepareForSegue)

From Dev

How to prevent UITableView from reuse custom cells Swift

From Dev

How do I reorder UITableView cells in Realm Swift?

From Dev

Remove the cells below the selected one from the UITableView Swift 3

From Dev

How to make only two cells of UITableview selectable at a time in swift

From Dev

Updating UITableView cells according to the text entered in a text filed that is in the same main view

From Dev

Updating uitableview datasource and updating tabbar

Related Related

  1. 1

    Swift - Reorder UITableView cells

  2. 2

    Swift : Clear UITableView Cells

  3. 3

    Swift - Fading cells in UITableView

  4. 4

    UITableView in Swift - dequeueing of cells

  5. 5

    Switching Custom Cells in UITableView in swift

  6. 6

    Cells not appearing in UITableView - Swift 3

  7. 7

    Updating Tableview Cells with a Button in swift

  8. 8

    Swift updating UITableView with new data

  9. 9

    Swift UITableView visually deselects cells on scroll

  10. 10

    UITableview with more than One Custom Cells with Swift

  11. 11

    Fail to hide empty cells in UITableView Swift

  12. 12

    getting data from each UITableView Cells Swift

  13. 13

    UITableView does not display the cells (using swift )

  14. 14

    How to hide specific cells in a static UItableview, in swift?

  15. 15

    UIImage not appearing in prototype cells in UITableView (Swift)

  16. 16

    How to hide specific cells in a static UItableview, in swift?

  17. 17

    Updating a UITableView in Swift from another ViewController

  18. 18

    Updating a UITableView in Swift from another ViewController

  19. 19

    Updating UITableView in another UIViewController without a segue in Swift

  20. 20

    UITableView not updating

  21. 21

    How to prevent UITableView from reuse custom cells Swift

  22. 22

    Swift 2.0, UITableView: cellForRowAtIndexPath returning nil for non-visible cells

  23. 23

    Swift - Segue from static UITableView with selected cells text (prepareForSegue)

  24. 24

    How to prevent UITableView from reuse custom cells Swift

  25. 25

    How do I reorder UITableView cells in Realm Swift?

  26. 26

    Remove the cells below the selected one from the UITableView Swift 3

  27. 27

    How to make only two cells of UITableview selectable at a time in swift

  28. 28

    Updating UITableView cells according to the text entered in a text filed that is in the same main view

  29. 29

    Updating uitableview datasource and updating tabbar

HotTag

Archive