Ios 如何从其他文件调用此重写函数
我正在尝试从另一个文件调用函数。另一个文件具有我需要的功能,swift不支持多重继承 我试图合并这个文件-Ios 如何从其他文件调用此重写函数,ios,swift,Ios,Swift,我正在尝试从另一个文件调用函数。另一个文件具有我需要的功能,swift不支持多重继承 我试图合并这个文件- import XLPagerTabStrip //Delete UIViewController, and Extend //ButtonBarPagerTabStripViewController instead class ParentViewController: ButtonBarPagerTabStripViewController { let purpleInspire
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]
}
您可以使用通用代码创建一些全局函数(在任何类之外),就我所知,您不需要任何参数
func instantiatePhoneAndMailViewControllers() -> [UIViewController] {
return [UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Phone"),
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Email")]
}
并从视图控制器(例如:)
中调用它
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
return instantiatePhoneAndMailViewControllers()
}