-1

I am using parse server to pass data to TableViewController.

I am able to retrieve data and append to my local arrays using parse. The arrays use a tableView. I have another ViewController called PostDataViewController which I segue to post new data. When I press the post button on the PostDataViewController, I immediately dismiss the ViewController. I call TableViewController.modalPresentationStyle = .fullScreen to enable viewDidAppear().

What I want to be able to do is to upon viewDidAppear(), add only new data from parse to my arrays. My temporary solution is delete all data from all arrays and run the initial query again. But this seems like this wastes a lot of energy & money.

Thanks :)

magellan
  • 63
  • 7

1 Answers1

0

I do something similar through protocol/delegate. So TableViewController that hold all of your data can append the new information from PostDataViewController and then reload your tableview to refresh the new posted data. But to get the data from PostDataViewController, I would use something like that

//Function to make your tableviewcontroller conform into it
protocol PostedDataDelegator{ 
func collectDataToParse(postedData: YourDataType)
}

//In your PostDataViewController
class PostDataViewController { 
let delegate: PostedDataDelegator?

//to send the data from the post button 
func postButtonAction(){ 
delegate.collectDataToParse(postedData: YourDataType)
}


}
//In your TableViewController
class TableViewController: UITableViewController, PostedDataDelegator {

//in your segue function you can have something like
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "Show"
    {
        if let postDataViewController = segue.destinationViewController as? PostDataViewController {
postDataViewController.delegate = self
        }
    }
}

func collectDataToParse(postedData: YourDataType){ 
yourArray.append(postedData)
tableview.reloadTable
}
}

Also I recommend watching videos by Sean Allen

Mohammed Zaki
  • 131
  • 1
  • 10