0

On my ViewController I have a logout button and a label which outputs the current username. On logout action, I would like to the log the user out but stay on the controller - I just want to refresh the view - is that possible?

user1555112
  • 1,897
  • 6
  • 24
  • 43

2 Answers2

0

add a timer to check if the user logout out ever .02 seconds. try to use this code let delayInSeconds = 3.0

        let delayInNanoSeconds = dispatch_time(DISPATCH_TIME_NOW, Int64(delayInSeconds * Double(NSEC_PER_SEC)))

        let concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

        dispatch_after(delayInNanoSeconds, concurrentQueue, {
        // task
            exit(0)
        })
0

You can simply hide the logout button and the username label. Just make sure you run the code on the main queue; if you run it as a delegate/action to a tap of a button you don't have to worry - you're already on the main queue.

@IBAction func didTapLogut(sender: AnyObject) {
    logutButton.hidden = true
    usernameLabel.text = "guest"
}

If you want to hide bar item, see here

If you want to change a view on a different queue (such as within some networking framework block) make sure you dispatch on the main queue (though I believe this is not the issue since logging user out does not involve anything running on a different queue - I'm just mentioning it because of a different answer you got here).

Community
  • 1
  • 1
surui
  • 1,522
  • 12
  • 17