【问题标题】:XCode IOS Beginner UIViewController Class change with buttonXCode IOS初学者UIViewController类更改按钮
【发布时间】:2012-11-14 10:01:23
【问题描述】:

我是编程新手,我整晚都在寻找,很长时间以来都想弄清楚这一点。不能......我不想使用导航控制器,但我想做的是这个。

所以我的项目中有两个类。 1 类和 2 类。现在 Class1 中有一个按钮。如果按下此按钮,我希望屏幕转到 Class2。我得到的最接近的是创建一个父类,但是当我这样做时,按钮仍保留在两个类上。

- (IBAction)addScheduleB:(id)sender {
    [UIView beginAnimations:@"View Curl" context:nil];
    [UIView setAnimationDuration:1.00];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if (self.firstScreen.view.superview ==nil){
        if(self.firstScreen==nil) {
            self.firstScreen = [[FirstScreen alloc] initWithNibName:@"FirstScreen" bundle:nil];
        }
        [self.config1.view removeFromSuperview];
        [self.view insertSubview:self.firstScreen.view atIndex:0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
        [self.config1.view removeFromSuperview];
        [self.view insertSubview:self.firstScreen.view atIndex:0];
        [sender setTitle:@"Switch To DVR"];

    }
    else{
        if(self.config1 == nil){
            self.config1 = [[Config1 alloc] initWithNibName:@"Config1" bundle:nil];
        }
        [self.firstScreen.view removeFromSuperview];
        [self.view insertSubview:self.config1.view atIndex:0];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
        [self.firstScreen.view removeFromSuperview];
        [self.view insertSubview:self.config1.view atIndex:0];
        [sender setTitle:@"Switch To TV"];
    }
    [UIView commitAnimations];
}

我想删除父类,只保留两个类。

是否有可能在 class1 内有一个按钮,按下时会将我带到 class2 ???

【问题讨论】:

  • 您想从一个视图转到另一个视图吗?

标签: ios xcode uiviewcontroller uibutton


【解决方案1】:

YouTube Here 上有一个 7 分钟的教程。这显示了如何使用不带情节提要的按钮从一个视图移动到另一个视图,因此您将能够学习代码以从一个类移动到另一个类。

我希望这会有所帮助。至于作为初学者,如果您浏览 youtube,您会发现很多教程可以帮助您学习。 :)

编辑:这不使用导航控制器

【讨论】:

  • 我真的很愚蠢,我知道这一点。我已经有几个星期没有编码了,我是一个初学者。我为此浪费了一天的时间。我也一直在输入presentViewController 而不是presentViewController。非常感谢。我希望我早点发布。我会定义的。发帖前先搜索 youtube。
【解决方案2】:

我希望这个解决方案可以帮助你 只需从 Class2 制作对象,当按下 Button1 时将 Class2 的 object.View 作为子视图添加到 Class1.view

祝你好运

【讨论】:

  • 发帖者明确表示不想使用导航控制器(无论出于何种原因)
  • @whiteagle 好的,谢谢我想念它
【解决方案3】:

尝试类似:

- (IBAction)flipViews {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.6f];

if ([saisieCompleteView superview])
{
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    [saisieCompleteView removeFromSuperview];
    [self.view addSubview:saisieRapideView];
    [self.view sendSubviewToBack:saisieCompleteView];
}
else {
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    [saisieRapideView removeFromSuperview];
    [self.view addSubview:saisieCompleteView];
    [self.view sendSubviewToBack:saisieRapideView];
}

[UIView commitAnimations];
}

saisieCompleteView 和 saisieRapideView 都必须是主视图的子视图。

【讨论】:

    【解决方案4】:

    您可以使用模态翻转过渡弹出另一个视图:

    [self presentViewController:Class2 animated:YES completion:^{
            // Some code on completeion
     }];
    

    关闭 Class2 视图:

    [self dismissViewControllerAnimated:YES completion:^{
        //code
    }];
    

    如果你不想退出当前的视图控制器,你可以这样翻转它:

    BOOL toShowSecond = YES;
    

    ...

    [UIView transitionWithView:self.view
                      duration:1.0
                       options:(toShowSecond?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight)
                    animations:^{
                        if(toShowSecond) {
                            firstView.hidden = YES;
                            secondView.hidden = NO;
                        } else {
                            firstView.hidden = NO;
                            secondView.hidden = YES;
                        }
                    }
                    completion:^(BOOL finished){
                        toShowSecond = !toShowSecond;
                    }];
    

    【讨论】:

      猜你喜欢
      • 2021-06-06
      • 2013-12-31
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多