我在互联网上搜索了一个解决方案但找不到任何可以解决我问题的方法。如何将变量或参数从一个函数传递到另一个函数。这是我的代码:
//BaseSplitViewController.swift
class BaseSplitViewController: UISplitViewController {
override func viewDidLoad() {
super.viewDidLoad()
let searchIcon = UIImage.fontAwesomeIcon(name: .search, textColor: UIColor.black, size: CGSize(width: 40, height: 40))
let baseSplitViewBarItem = UITabBarItem(title: "Search", image: searchIcon, selectedImage: searchIcon)
self.tabBarItem = baseSplitViewBarItem
}
}
//FavoritesNavigationController.swift
class FavoritesNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
let favIcon = UIImage.fontAwesomeIcon(name: .star, textColor: UIColor.black, size: CGSize(width: 40, height: 40))
let favViewBarItem = UITabBarItem(title: "Favorits", image: favIcon, selectedImage: favIcon)
self.tabBarItem = favViewBarItem
}
}
答案 0 :(得分:1)
要使用另一个函数中的值,您有两个选项。
您可以将该值存储在相同或更高范围内的变量中,也可以将该值作为函数参数传递。
function a()
b(3)
end
function b(value)
print(value)
end
a()
3
或
local value
function a()
value = 3
end
function b()
print(value)
end
a()
b()
3