【发布时间】:2012-01-15 00:23:52
【问题描述】:
我将UIViewController 子类化为STViewController,并注意到从STViewController 继承的类的viewDidLoad 方法被重复调用。最终使应用程序崩溃。 STViewController 在这一点上基本上是一个空白的实现。我的子类化如下所示:
#import "STViewController.h"
@interface WelcomeViewController : STViewController {
STViewController.h
#import <UIKit/UIKit.h>
@interface STViewController : UIViewController
{
}
@end
STViewController.m
#import "STViewController.h"
@implementation STViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
// Implement loadView to create a view hierarchy programmatically, without using a nib.
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
来自 WelcomeViewController.m 的 viewDidLoad()
- (void)viewDidLoad
{
[super viewDidLoad];
// hide the buttons
[[self signUp] setHidden: YES];
[[self logIn] setHidden: YES];
}
【问题讨论】:
-
我们能看到'空白实现吗? (STViewController)
-
viewDidLoad实现在WelcomeViewController和STViewController中的表现如何? -
用这些细节更新了帖子。
标签: objective-c ios xcode uiviewcontroller subclass