我使用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