我使用presentModalDialog来显示viewcontroller的视图,但是viewDidLoad永远不会被调用?!未使用presentModalDialog方法调用viewDidLoad方法
是否有任何方法可以调用我的逻辑来填充和配置视图?
编辑:
这是一个有点难以放在一个很小的代码量,你有种需要看到这一切,但这里有云:
我有两个笔尖和2个视图控制器(纵向状态mainvc/landscape),它们都从具有逻辑和iboutlets的1个基类继承而来。这是为了让我重新使用代码。当主控制器中的方向改变时,它在两个控制器(模态对话框)之间切换,而这两个控制器又使用它们各自的笔尖,但是它们都使用相同的基本代码来配置UI项目。
@implementation HomeViewControllerBase
- (void)configureBestSellItems
{
[self startRetrievingRegions];
// load all the images from our bundle and add them to the scroll view
// NSUInteger i;
for (int i = 0; i <= 150; i++)
{
NSString *imageName = @"tempImage.jpg";
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i; // tag our images for later use when we place them in serial fashion
[self.bestSellScrollView addSubview:imageView];
[imageView release];
}
[self layoutScrollImages]; // now place the photos in serial layout within the scrollview
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureBestSellItems];
}
@end
@interface HomeViewController : HomeViewControllerBase
{
}
@interface HomeViewController_Landscape : HomeViewControllerBase
{
}
@implementation HomeViewController
//This works for portrait
- (void)viewDidLoad
{
[super viewDidLoad];
}
@end
@implementation HomeViewController_Landscape
//This does not work
- (void)viewDidLoad
{
[super viewDidLoad];
}
//This works as suggested
- (void)awakeFromNib
{
[super configureBestSellItems];
}
@end
你能提供一些代码吗?听起来很奇怪,你有没有想过调用viewDidLoad的超类实现? – LuckyLuke 2011-04-11 19:55:21
+1发布一些代码。 'viewDidLoad'将永远被调用,所以在你的实现中有一些东西。 – XJones 2011-04-11 20:59:25
@Andreas - 我已经添加了一些代码,很想听听您的意见 – TheLearner 2011-04-12 08:33:01