I tried to update my navigationItem titleView when I finished downloading data model from server.
Something like this :
private func loadNews() {
self.newsModelManager.sendRequest(inBackground: false, preSendHandler: { (isReachable) in
if isReachable {
} else {
appDelegate.showInternetFailedAlertView()
}
}, successHandler: { (response) in
print("loadNewsModel: successHandler")
}, errorHandler: { (response) in
print("loadNewsModel: errorHandler")
}, reloginFailHandler: { (response) in
appDelegate.showReloginFailedAlertView()
}) { (isReachable) in
let array = self.newsModelManager.loadFirstFiveNews()!
DispatchQueue.main.async {
self.setupTitle_ViewWith(array: array)
}
}
}
func setupTitle_ViewWith(array: [NewsModel]?) {
guard array != nil else { return }
let frame = CGRect(x: 0, y: 0, width: 200, height: 40)
let newsTitle_View = NewsTitleView(newsModelArray: array!, frame: frame)
newsTitle_View.newsTitleViewDelegate = self
self.title_View = newsTitle_View
}
self.title_View = newsTitle_View
let array = self.newsModelManager.loadFirstFiveNews()!
Hi here is the brief summary of what solved this issue for reference for others who might face the similar kind of issue,
The codes which @Ian has shared in the question has been added in the NavigationController subclass.
The issue is caused here. Because you cannot able to update the navigation title nor the titleView from the navigation controller for little explanation refer this answer(https://stackoverflow.com/a/20923010/4510873)
So we tried updating the titleView from viewController and it solved our issue then.