gpt4 book ai didi

xcode - 从文件更改导航栏的标题

转载 作者:行者123 更新时间:2023-11-30 14:17:29 25 4
gpt4 key购买 nike

所以我有一个导航栏,并且希望能够更改它的标题并将文本文件的内容显示为标题。我打算使用此代码来访问标题 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}

谢谢

最佳答案

只需将 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}
}

关于xcode - 从文件更改导航栏的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30954277/

25 4 0