所以我有一个导航栏,希望能够更改它的标题并显示文本文件的内容作为标题。我打算使用此代码来访问标题self.navigationItem.title = "YourTitle"
,并想知道是否有人可以锻炼我如何混合以下从文本文件中检索的代码:
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}
由于
答案 0 :(得分:0)
只需将self.DescriptionText.text =
替换为self.navigationItem.title =
这是完整的代码:
//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}
}