MainMenuViewController以模态方式呈现BonusViewController。我想解雇BonusViewController,然后显示一个新的BonusViewController,有效地“重置”BonusViewController。
我使用通知在MainMenuViewController中调用此方法
-(void)resetBonus{
[self dismissViewControllerAnimated:YES completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
我期望BonusViewController被自动检测,因为我在上面的presentViewController调用中输入它但是它没有,我的viewControllers都没有出现,因为我输入我假设意味着我这样做完全错了。我是否必须初始化VC或分配它才能像这样展示它?或者我甚至可以这样做,因为我使用故事板?
虽然我认为这种方法已弃用
,但我也试过了-(void)resetBonus{
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: BonusViewController animated:NO ];
}
Sumanth的建议是什么,但我现在收到了这条消息:
所以现在我在做:
#import "BonusViewController.h
....
-(void)resetBonus
{
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:NO];
[self presentModalViewController: bonus animated:NO ];
}
错误全部消失但是当BonusViewController出现时,显示器是纯黑色的,我可以听到声音但是无法在屏幕上看到任何内容
答案 0 :(得分:1)
你应该分配并初始化viewcontroller并使用presentModalViewController
这样写出
BonusViewController *bonus = [[BonusViewController alloc]init];
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController: bonus animated:NO ];
答案 1 :(得分:1)
也不要忘记在.h文件中写#import“BonusViewController.h”
BonusViewController *objBonus = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:objBonus animated:YES completion:NULL];
您需要创建viewcontroller的对象并直接传递viewcontroller,这是不可能的
答案 2 :(得分:0)
#import "BonusViewController.h"
-(void)resetBonus
{
BonusViewController *BonusViewController = [[BonusViewController alloc]init];
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController: BonusViewController animated:NO completion:nil];
}
设置两个动画都是否
编辑:#import "BonusViewController.h"
答案 3 :(得分:0)
我确定给出的答案是正确的,但我无法使它们正常工作。出于某种原因,BonusViewController似乎显示为我可以听到声音,但屏幕是黑色的,没有任何东西在视觉上显示。
我最近在最近的时间里做了下面的事情,但这不是我真正想要的顺利效果。
当我有更多时间想出更好的方法时,我必须重新访问它。
-(void)endBonus
{
[self dismissViewControllerAnimated:NO completion:^{
[self performSelector:@selector(resetBonus) withObject:nil afterDelay:1];
}];
}
-(void)resetBonus
{
[self performSegueWithIdentifier: @"segueToBonus" sender: self];
}