我正在尝试从另一个文件调用函数。另一个文件具有我需要的功能,而swift不支持多重继承。
我正在尝试合并此文件-
import XLPagerTabStrip
//Delete UIViewController, and Extend //ButtonBarPagerTabStripViewController instead
class ParentViewController: ButtonBarPagerTabStripViewController {
let purpleInspireColor = UIColor(red:0.13, green:0.03, blue:0.25, alpha:1.0)
override func viewDidLoad() {
super.viewDidLoad()
// change selected bar color
settings.style.buttonBarBackgroundColor = .white
settings.style.buttonBarItemBackgroundColor = .white
settings.style.selectedBarBackgroundColor = purpleInspireColor
settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 14)
settings.style.selectedBarHeight = 2.0
settings.style.buttonBarMinimumLineSpacing = 0
settings.style.buttonBarItemTitleColor = .black
settings.style.buttonBarItemsShouldFillAvailiableWidth = true
settings.style.buttonBarLeftContentInset = 0
settings.style.buttonBarRightContentInset = 0
changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }
oldCell?.label.textColor = .black
newCell?.label.textColor = self?.purpleInspireColor
}
}
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Phone")
let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Email")
return [child_1, child_2]
}
}
带有此文件-
import Foundation
import UIKit
class SignupViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func loginTapped(_ sender: Any) {
let loginViewController = storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
present(loginViewController,animated: true, completion: nil)
}
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Phone")
let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Email")
return [child_1, child_2]
}
}
但是,它们从两个不同的基类继承,所以什么都没有起作用。
我想将这两个类放置在单独的文件中,并从需要使用的文件中调用该类中的函数,但是在调用此特定函数时,参数存在问题。
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Phone")
let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Email")
return [child_1, child_2]
}
答案 0 :(得分:0)
您可以使用通用代码创建一些全局函数(在任何类之外),据我所知,您不需要任何参数
<div class="top-sm">
<ul>
<li><a href="#"><i class="fab fa-facebook-f"></i>1</a></li>
<li><a href="#"><i class="fab fa-twitter"></i>2</a></li>
<li><a href="#"><i class="fab fa-linkedin-in">3</i></a></li>
<li><a href="#"><i class="fab fa-youtube"></i>4</a></li>
</ul>
</div>
并从func instantiatePhoneAndMailViewControllers() -> [UIViewController] {
return [UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Phone"),
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Email")]
}
等内部调用它。例如
viewControllers(for:)