【问题标题】:Switching between UIViewController - presentViewController在 UIViewController - presentViewController 之间切换
【发布时间】:2012-12-11 03:08:48
【问题描述】:

以下代码不适合我。每当调用该方法时,应用程序就会崩溃我做错了什么?

此代码确实使用故事板格式

在 .h 文件中

@class SendVideoViewController;

...

@property (nonatomic) SendVideoViewController *sendVideoViewController;

在 .m 文件中

#import "SendVideoViewController.h"
...
@synthesize sendVideoViewController;
...
- (IBAction)signMeUpButtonPressed:(id)sender {
termsAndConditionsViewController = [[TermsAndConditionsViewController alloc] init];
[self presentViewController:termsAndConditionsViewController animated:YES completion:nil];
//[self.view insertSubview:termsAndConditionsViewController.view atIndex:0];
}

【问题讨论】:

  • 如果我能从这个网站得到一些可靠的反馈就更好了。如果您发布答案,请回复该答案的 cmets。我不喜欢被告知要写什么,我也想知道它是什么意思

标签: iphone uiviewcontroller ios6


【解决方案1】:

您的代码应为:

sendVideoViewController = [[SendVideoViewController alloc] init];
[self presentViewController:sendVideoViewController animated:YES completion:nil];

现在您正在实例化一个通用的UIViewController 类。为了创建您在SendVideoViewController 类中定义的类型的对象,您需要在该类上调用+alloc,而不是UIViewController。你可能想复习the documentation

【讨论】:

  • 非常感谢。我很高兴你解释了它。我在这里看到的大多数答案只是直接的代码。但谢谢你帮助我理解
  • 这段代码只会出现黑屏...我需要在窗口中插入子视图吗?
  • 顺便说一句,我正在使用故事板
  • 没有。如果没有子视图并且背景颜色为黑色,则可能是黑屏。您是否在情节提要中设置了视图?
【解决方案2】:

试试这个:

sendVideoViewController = [[SendVideoViewController alloc] init];
[self presentViewController:sendVideoViewController animated:YES completion:nil];

【讨论】:

  • 这不起作用...我需要将视图添加到子视图吗?
  • 请把代码贴出来让我们看到就好了
  • 这是所有必要的代码。 “视图切换器”代码位于一个 void 方法中,当触摸情节提要上的按钮时调用该方法,但它会使应用程序崩溃
猜你喜欢
  • 1970-01-01
  • 2014-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多