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

标签 xcode swift text-files navigationbar

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

相关文章:

xcode - 从扩展坞菜单中删除 Xcode 最近的项目

ios - Swift - 创建自定义捕获 session 预设

ios - 为什么屏幕外的 UICollectionViewCells 不会更新?

sql - 选择查询固定长度

c++ - 用 cocos2d-x 3.6 实现 ScrollView

swift - FireStore Swift 4 : How to get total count of all the documents inside a collection, 并获取每个文件的详细信息?

swift - GoogleWebRTC 挂起(卡住)swift native 应用程序(OpenVidu)中的主线程

java - 使用scanner/reader/bufferedreader读取文本文件以读取.txt文件中的数字

c - 如何检查 c 中 fscanf 的行为?

ios - 架构 i386 的重复符号