0

我在我的代码上遗漏了一个明显的点,但我看不到在哪里。

TermsViewController *termsVC = [[TermsViewController alloc] init];
termsVC.signUpVC = self;
[self presentViewController:termsVC animated:YES completion:nil];

调用该方法时presentViewController,我可以看到该方法viewDidLoad已在我的身上调用,TermsViewController但除了黑屏之外没有任何内容。

当我有termsVC.view.backgroundColor = [UIColor greenColor];我可以看到一个绿屏。当我深入查看调试器时,我可以看到我的控制器已初始化,但我的组件(UITextField + UIButton)是nil. 我认为presentViewController已加载链接到控制器的视图,但最终没有。

这是我的条款视图控制器:

#import "TermsViewController.h"

@interface TermsViewController ()

@end

@implementation TermsViewController
@synthesize signUpVC;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = [[NSString alloc] initWithFormat:@"Test"];
    acceptButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

    // Do any additional setup after loading the view.
}
4

1 回答 1

0

You need to load your view controller from the storyboard, try this:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"<YourStoryboardFileName>" 
                                                     bundle:nil];
TermsViewController *termsVC = [storyboard instantiateViewControllerWithIdentifier:@"<TermsViewController Storyboard ID>"];
termsVC.signUpVC = self;
[self presentViewController:termsVC animated:YES completion:nil];
于 2014-04-27T10:01:35.540 回答