ios - Swift IOS : several buttons in one view controller, 在另一个 View Controller 中控制 ImageView 显示

标签 ios iphone

我只想在一个 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/

相关文章:

iphone - 在启动时发送的所有本地通知

objective-c - 您如何知道用户何时选择通过AirPlay播放视频?

ios - Swift Sprite 套件 : How do you set an animation for a random time?

javascript - MobileSafari 不会发回使用 CORS 设置的 Cookie

iphone - 邮件撰写 View Controller 导航栏

javascript - iPhone iWebKit 复制到剪贴板

ios - UICollectionView didSelectIotemAt issue

ios - 使用 FFmpeg 在 iOS 上编写时将 fMP4 转码为 HLS

iOS 10.0.1 和 Xcode 错误 : "Could not find developer disk image"

iphone - 关于iPhone上URL中NSString字符无效的问题