我只想在一个 View Controller (#1)中使用 30 个按钮,当我单击其中一个按钮(例如 Button1)时,屏幕可以跳转到另一个 View Controller (2),并显示图片 1。当我回到 View Controller (#1),并点击按钮 2 时,它可以跳转到 View Controller (#2)并显示图片 2...等等。我可以使用 segues 切换两个 View Controller ,但是如何控制不在同一个 View Controller 中的 ImageView 的内容?谢谢。
最佳答案
您需要使用 prepareForSegue 方法来设置其他 Controller 中的变量。在您的第二个 Controller 中,您的属性需要公开。
objective-C
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"YOURSEGUENAME"]) {
secondControllerViewController * secController = [[secondControllerViewController alloc] init];
[secController setImageName:@"imagenameTeste"];
}
}
swift
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "yourSegue") {
// pass data to next view
}
}
关于ios - Swift IOS : several buttons in one view controller, 在另一个 View Controller 中控制 ImageView 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32405530/