Reputation: 5187
Sorry for my english
In my app, i have a login form. If the username and password are good,
the username is stored in a keyChain and it goes back to the main viewController using: self.navigationController.popToRootViewControllerAnimated(true)
The data is loaded by a php file that use the username to get data from that username
And in the main viewController their is a tableView that contain the data
But the problem is that after the connection, the tableView does not change. It only change if i restart the app
My code to get the data:
@IBOutlet var tblTask: UITableView!
let bodyData = "username=" + username!
let URL: NSURL = NSURL(string: "link to php file")
let request:NSMutableURLRequest = NSMutableURLRequest(URL:URL)
request.HTTPMethod = "POST"
request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue())
{
(response, data, error) in
var output = NSString(data: data, encoding: NSUTF8StringEncoding)
var array = self.JSONParseArray(output)
for var i = 0, a = 1 ; i < array.count ; i += 2, a += 2 {
if(a > 0 && i > 0)
{
self.arrayDate.append(array[i])
self.arrayPoid.append(array[a])
}
}
for var i = 0; i < self.arrayDate.count ; i++ {
self.arrayPoid[i] += " livres"
}
self.tblTask.reloadData()
}
Upvotes: 1
Views: 1072
Reputation: 92569
I think Unwind Segues are what you need. You can set them with only a few steps. Add this method in your rootViewController:
@IBAction func reset(segue: UIStoryboardSegue) {
tableView.reloadData()
}
In Interface Builder, create UIButtons
in any viewController that would need to go back to rootViewController. Then link each of these UIButtons
to the red "Exit" button of their respective viewController and select reset: in the pop-up menu that appears (see the images below).
When you will click on those buttons, you will be brought back to your rooViewController and reset:
will be performed (with your tableView reloaded).
See WWDC 2012 session video "Adopting Storyboards in Your App" for more details about unwind segues [starts at 38 minutes].
Upvotes: 1
Reputation: 44818
Try the call self.tableView.reloadData()
in the UITableViewController
's viewWillAppear
method. Does that solve it?
Upvotes: 0