如果我的“按钮"在视图控制器 1 上选择,然后图像应该显示并留在视图控制器 2 上 [英] if my "button" is selected on view controller 1, then image should then display and stay on view controller 2

查看:20
本文介绍了如果我的“按钮"在视图控制器 1 上选择,然后图像应该显示并留在视图控制器 2 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户在视图控制器 1 上选择了我在下面创建的按钮/复选框",那么我希望图像(出现)显示在视图控制器 2 上.

If the "button/checkbox" I have created below is selected by the user on view controller 1, then I would like an image to (appear) display on view controller 2.

如果我离开视图控制器 2 屏幕并返回视图控制器 2 屏幕,只要视图控制器 1 上的按钮仍处于选中状态,图像仍应显示.

if i leave view controller 2 screen and come back to view controller 2 screen, the image should still display as long as the button is still selected on view controller 1.

如果视图控制器 1 上不再选择按钮",则图像不应再显示在视图控制器 2 上.

if the "button" is no longer selected on view controller 1, then the image should no longer be displayed on view controller 2.

请注意,上面提到的按钮/复选框"是由下面的代码创建的.请帮忙,谢谢.

  • (IBAction)checkButton2:(id)sender {如果 (!checked2) {

  • (IBAction)checkButton2:(id)sender { if (!checked2) {

[_checkBoxButton2 setImage:[UIImage imageNamed:@"checkBoxMarked.png"] forState:UIControlStateNormal];
checked2 = YES;

    // alert placeholder
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Locked" message:@"this is locked." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
    [alert show];

    [_checkBoxButton2 setImage:[UIImage imageNamed:@"checkBox.png"] forState:UIControlStateNormal];
    checked2 = NO;

}

else if (checked2) {

else if (checked2) {

[_checkBoxButton2 setImage:[UIImage imageNamed:@"checkBox.png"] forState:UIControlStateNormal];
checked2 = NO;

// alert placeholder
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Character selection:" message:@"The box is no longer selected." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Cancel", nil];
[alert show];

}}

推荐答案

您应该将 View 嵌入到导航控制器中.

You should Embed you View into a navigation controller.

当你按下 Next Screen 时,执行一个 segue:

When you press Next Screen, perform a segue:

- (IBAction)nextBtn:(id)sender {
    [self performSegueWithIdentifier:@"segue" sender:self];
}

在继续之前,设置一个 BOOL 标志以确定它是否应该显示:

before you segue, set a BOOL flag to determine if it should display or not:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"step2Segue"]){
        ImageViewController *controller = (ImageViewController *)segue.destinationViewController;
        controller.displayImage = checked2;
    }
}

最后在 ImageViewController 中添加一个基于 Bool 的条件来确定是否应该显示它:在 .h

Finaly in the ImageViewController add a condition based on the Bool to determine if you should display it or not: in .h

@interface ImageViewController : ViewController
@property (strong, nonatomic) IBOutlet UIImageView *image;
@property (nonatomic, assign) BOOL displayImage;
@end

.m

-(void)viewDidLoad{
    if (self.displayImage) {
        self.image.hidden = YES;
    }else{
        self.image.hidden = NO;
    }
}

这篇关于如果我的“按钮"在视图控制器 1 上选择,然后图像应该显示并留在视图控制器 2 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆