- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个 View Controller 。第一个 UIViewController 'DiscrimUIViewCollection' 有 5 个按钮,每个链接到 swift 文件中的一个 @IBAction func showAdvicePopUp(_ sender: UIButton)。我可以成功使用 print(sender.currentTitle) 并将标题打印到 5 个按钮中的每一个。
在第二个 View Controller “PopUpViewContoller”中,我有一个 UILabel,我想从第一个 Controller 的发件人按钮的标题中设置文本。
我已经在这 2 天了,找不到答案。
我想要 var updateTheLabel: String 的值?从“DiscrimUIViewCollection”接收 sender.currentTitle,我认为这一切都会起作用。
我在 main.storyboard 上没有任何 Segue 箭头,因为我都是以编程方式完成的。
我已经包含了下面的代码供您查看。
提前致谢。
class DiscrimUIViewCollection: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
public var buttonText = ""
@IBAction func showAdvicePopUp(_ sender: UIButton) {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "advicePopUpID") as! PopUpViewController
self.addChild(popOverVC)
popOverVC.view.frame = self.view.frame
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: (self))
buttonText = sender.currentTitle!
print(sender.currentTitle!)
print(buttonText) //THIS WORKS!
}
func prepareForSegue(segue: UIStoryboardSegue, sender: UIButton?) {
//if segue.identifier == "advicePopUpID" {
let controller = segue.destination as! PopUpViewController
controller.updateTheLabel = buttonText
//}
}
}
这是 PopUpViewController 文件:
class PopUpViewController: UIViewController {
// This file is to set the setting of the UIView Controller and how it appears.
//var desiredLabelValue: String?
var updateTheLabel: String?
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.6)
self.showAnimate()
adviceTitle.text = updateTheLabel
//print(updateTheLabel!)
//adviceTitle?.text = desiredLabelValue
//To set the text of Header
//adviceTitle?.text = "Yellow Advice"
// Do any additional setup after loading the view.
}
@IBAction func closePopUp(_ sender: Any) {
//self.view.removeFromSuperview()
//self.removeAnimate()
print(updateTheLabel)
}
func showAnimate() {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0
//popUpArea.backgroundColor = colourOrange
UIView.animate(withDuration: 0.25, animations: {
self.view.alpha = 1.0
self.view.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
//print(self.adviceText!)
//print(self.adviceTitle!)
//self.adviceTitle?.text = "Yellow Advice"
//self.adviceTitle?.text = self.desiredLabelValue
//print(self.adviceTitle?.text!)
//Set the Background Colour of the popup box
//depending on what the Title states.
if self.adviceTitle.text == "Red Advice" {
self.popUpArea.backgroundColor = mtsRed
} else if self.adviceTitle?.text == "Orange Advice" {
self.popUpArea.backgroundColor = mtsOrange
} else if self.adviceTitle.text == "Yellow Advice" {
self.popUpArea.backgroundColor = mtsYellow
} else if self.adviceTitle.text == "Green Advice" {
self.popUpArea.backgroundColor = mtsGreen
} else if self.adviceTitle.text == "Blue Advice" {
self.popUpArea.backgroundColor = mtsBlue
}
})
}
func removeAnimate() {
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
self.view.alpha = 0.0;
}) { (success:Bool) in
self.view.removeFromSuperview()
}
}
@IBOutlet weak var adviceTitle: UILabel!
@IBOutlet weak var adviceText: UILabel!
@IBOutlet weak var popUpArea: UIView!
}
最佳答案
您可以呈现 popOverVC 并传递数据。如果您想以全屏方式呈现它,则无需为其分配框架并将其添加为 subview 。
@IBAction func showAdvicePopUp(_ sender: UIButton) {
let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "advicePopUpID") as! PopUpViewController
buttonText = sender.currentTitle!
popOverVC.updateTheLabel = buttonText
popOverVC.modalPresentationStyle = .fullScreen // to present on full screen
self.present(popOverVC, animation : true, completion : nil)
}
关于ios - 将 sender.currentTitle UIButton 文本发送到 PopUpViewController 中的 UILabel 而不是发送到 PopUpViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59261455/
我有两个 View Controller 。第一个 UIViewController 'DiscrimUIViewCollection' 有 5 个按钮,每个链接到 swift 文件中的一个 @IBA
我正在使用 TTLauncherView,为此我将 View Controller 声明为 TTViewController,如 TTCatalog 教程应用程序中所示。在该 View 中声明一个 T
我使用 NMPopUpView当用户触摸表格 View 行时显示弹出窗口。当我滚动表格 View 并触摸一行时,问题就出现了,弹出窗口出现在表格 View 的顶部。 当用户使用以下代码触摸该行时,我通
这个问题在这里已经有了答案: Passing data between view controllers (45 个答案) 关闭 3 年前。 我有两个 View Controller :一个是普通
我想将 datepicker.date 从 DatePickerPopupViewController 传递到我的 SensorvViewcontroller,如下所示。但是,它返回我“null”。我
我需要在 viewcontroller 中调用一个方法,从创建的 popupviewcontroller 创建一个 popupviewcontroller。 对于 iPad,我是这样创建的: if (
我是一名优秀的程序员,十分优秀!