Connor Brough Connor Brough - 1 year ago 95
iOS Question

How can I reload tableview within my TableViewController within button action?

Currently I have the following code which saves an object however I am wanting to update/reload the tableview. The button isn't attached to a cell/row it's top right within my navigation controller (plus icon)

Note: Everything is happening within the same scene therefore any events attached to segue where I could reload table data is out of the question.

@IBAction func addWeek (sender: UIButton){

let newnumber:Int = routineWeeks.count + 1

// save data using cor data managed object context
if let managedObjectContext = (UIApplication.sharedApplication().delegate as? AppDelegate)?.managedObjectContext {
week = NSEntityDescription.insertNewObjectForEntityForName("Weeks", inManagedObjectContext: managedObjectContext) as! Weeks

week.weekNumber = newnumber

do {
} catch {

//currently not reloading table with new data

//print information in console

print("end of save function, dismiss controller")


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)

// Configure the cell...
cell.textLabel?.text = "Week \(routineWeeks[indexPath.row].weekNumber)"

return cell

Thanks Stackoverflow community for pointing me in the right direction.

print("this is a new week:\(week)")

Answer Source
print("this is a new week:\(week)")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download