Changing title of navigation bar from a file

51 Views Asked by At

So I have a navigation bar and would like to be able to change it's title and display the contents of a text file as the title. I was going to use this code to get access to the title self.navigationItem.title = "YourTitle" and wanted to know if anyone could workout how I could blend the following code which retrieves from a text file:

 let descriptionTextUrl = NSURL(string: "https://wordpress.org/plugins/about/readme.txt")
    let descriptionTextRequest = NSURLRequest(URL: descriptionTextUrl!)

    NSURLConnection.sendAsynchronousRequest(descriptionTextRequest, queue: NSOperationQueue.mainQueue()) {
        (response, data, error) in
        dispatch_async(dispatch_get_main_queue())
            {self.DescriptionText.text = NSString(data: data, encoding: NSUTF8StringEncoding)! as String
                return}

Thanks

1

There are 1 best solutions below

0
On

It was simply a matter of replacing the self.DescriptionText.text = with the self.navigationItem.title =

This was the complete code:

 //NavBar
    let navigationBarUrl = NSURL(string: "https://wordpress.org/plugins/about/readme.txt")
    let navigationBarRequest = NSURLRequest(URL: navigationBarUrl!)

    NSURLConnection.sendAsynchronousRequest(navigationBarRequest, queue: NSOperationQueue.mainQueue()) {
        (response, data, error) in
        dispatch_async(dispatch_get_main_queue())
            {self.navigationItem.title = NSString(data: data, encoding: NSUTF8StringEncoding)! as String
                return}
    }