使用 swift 更改 UINavigationController 标题时出现延迟
Delay when changing UINavigationController title with swift
好的,我尝试了不同的方法来更新 UINavigationBar 中的标题,但总是有延迟。
我有一个导航控制器,它是 table 视图的根视图控制器。我尝试了不同的方法来更改标题并尝试让 UINavigationBar 重绘,但是有大约 10 秒的延迟。
//I have tried different ways to change the title:
self.title = str
//and
@IBOutlet var tableTitle: UINavigationItem!
self.tableTitle.title = str
//as well as different ways to convince it to redraw
self.view.window?.rootViewController?.setNeedsStatusBarAppearanceUpdate()
//and
self.tableTitle.awakeFromNib()
我忘了这是从 dataTaskWithURL 完成的,所以它需要从主线程调用。
尝试使用dispatch_async
,此函数提交一个块以在调度队列上异步执行并立即returns,看看下面的代码:
dispatch_async(dispatch_get_main_queue(), {
// Change your title here
})
希望对你有所帮助。
好的,我尝试了不同的方法来更新 UINavigationBar 中的标题,但总是有延迟。
我有一个导航控制器,它是 table 视图的根视图控制器。我尝试了不同的方法来更改标题并尝试让 UINavigationBar 重绘,但是有大约 10 秒的延迟。
//I have tried different ways to change the title:
self.title = str
//and
@IBOutlet var tableTitle: UINavigationItem!
self.tableTitle.title = str
//as well as different ways to convince it to redraw
self.view.window?.rootViewController?.setNeedsStatusBarAppearanceUpdate()
//and
self.tableTitle.awakeFromNib()
我忘了这是从 dataTaskWithURL 完成的,所以它需要从主线程调用。
尝试使用dispatch_async
,此函数提交一个块以在调度队列上异步执行并立即returns,看看下面的代码:
dispatch_async(dispatch_get_main_queue(), {
// Change your title here
})
希望对你有所帮助。