问题描述
我已经成功地从 CollectionViewController
-> MenuTableViewController
-> ListViewController链接链接的委托方法
。在 ListViewController
扩展名中,我调用 changeTitleView()
,但是它不起作用。但是,数据已成功传递,因为 print(title)
正确打印了传递的信息。如果从 ListViewController
changeTitle()
即可正确执行p $ p> class ListViewController {
var navigationTitle:字符串?
@objc func changeTitle(title:String){
let titleLabel = UILabel()
let属性:NSDictionary = [
NSAttributedStringKey.font:UIFont(name: HelveticaNeue,大小:20)!,
NSAttributedStringKey.foregroundColor:UIColor(红色:0.1137,绿色:0.1137,蓝色:0.149,alpha:0.8)/ *#1d1d26 * /,
NSAttributedStringKey.kern :CGFloat(2.0)
]
let attributedTitle = NSAttributedString(string:
title.uppercased(),attributes:attribute as?[NSAttributedStringKey:AnyObject])
titleLabel.attributedText = attributedTitle
titleLabel.sizeToFit()
self.navigationItem.titleView = titleLabel
}
}
扩展ListViewController:HandleTitleView {
@objc func changeTitleView(title:String){
print(title)
self.navigationTitle = title
changeTitle(title:navigationTitle!)
}
Additi全部信息:
1)我正在通过SWRevealController传递信息,因此并非所有数据都在同一导航堆栈中。 ListViewController
在 MenuTableViewController
之上,而 CollectionViewController
实例化自 MenuTableViewController
然后关闭
2)我在 预先感谢 ,您可以从此链接下载代码 I have successfully chain linked delegate methods from Additional information: 1) I am passing information through SWRevealController so not all data is within the same navigation stack. 2) I created a button in Thanks in advance and you can download the code from this link 这篇关于方法被调用,但执行不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! ListViewController $ c中创建了一个按钮$ c>调用
changeTitle()
并成功更改了 navigationItem.titleView
,因此我知道该方法有效。 / p>
@objc func changeTitle(title:String){
let titleLabel = UILabel()
let attributeFontSaySomething:[String:Any] = [NSFontAttributeName:UIFont(name: HelveticaNeue,size:20)吗? ? UIFont.systemFont(ofSize:20),NSForegroundColorAttributeName:UIColor(红色:0.1137,绿色:0.1137,蓝色:0.149,alpha:0.8),NSKernAttributeName:CGFloat(2.0)]
var属性= attributeFontSaySomething
let attStringSaySomething = NSAttributedString(字符串:title.uppercased(),属性:属性)
titleLabel.attributedText = attStringSaySomething
titleLabel.sizeToFit()
self.navigationItem.titleView = titleLabel
}
CollectionViewController
-> MenuTableViewController
-> ListViewController
. In ListViewController
extension I call changeTitleView()
but it is not working. The data, however is successfully passed because print(title)
correctly prints passed information. changeTitle()
executes properly if called from within ListViewController
class ListViewController {
var navigationTitle: String?
@objc func changeTitle(title: String) {
let titleLabel = UILabel()
let attributes: NSDictionary = [
NSAttributedStringKey.font:UIFont(name: "HelveticaNeue", size: 20)!,
NSAttributedStringKey.foregroundColor: UIColor(red: 0.1137, green: 0.1137, blue: 0.149, alpha: 0.8) /* #1d1d26 */,
NSAttributedStringKey.kern:CGFloat(2.0)
]
let attributedTitle = NSAttributedString(string:
title.uppercased(), attributes: attributes as? [NSAttributedStringKey : AnyObject])
titleLabel.attributedText = attributedTitle
titleLabel.sizeToFit()
self.navigationItem.titleView = titleLabel
}
}
extension ListViewController: HandleTitleView {
@objc func changeTitleView(title: String) {
print(title)
self.navigationTitle = title
changeTitle(title: navigationTitle!)
}
ListViewController
is on top of MenuTableViewController
and CollectionViewController
is instantiated from MenuTableViewController
and then dismissedListViewController
that calls changeTitle()
and it successfully changes the navigationItem.titleView
so I know the method works. @objc func changeTitle(title: String) {
let titleLabel = UILabel()
let attributeFontSaySomething : [String : Any] = [NSFontAttributeName : UIFont(name: "HelveticaNeue", size: 20) ?? UIFont.systemFont(ofSize: 20) ,NSForegroundColorAttributeName :UIColor(red: 0.1137, green: 0.1137, blue: 0.149, alpha: 0.8),NSKernAttributeName : CGFloat(2.0) ]
var attributes = attributeFontSaySomething
let attStringSaySomething = NSAttributedString(string: title.uppercased(), attributes: attributes)
titleLabel.attributedText = attStringSaySomething
titleLabel.sizeToFit()
self.navigationItem.titleView = titleLabel
}