我在我的主视图控制器中有这个方法:
-(void)showDialog {
if (stopDialogController == nil)
stopDialogController = [[StopDialogController alloc] initWithNibName:@"StopDialog" bundle:nil WithStop:@"CLAS"];
if (stopDialogController)
[stopDialogController presentWithSuperview:self.view withStopName:@"Evan Kimia"];
}如果我使用self showDialog从同一个视图控制器中调用它,那么它可以很好地执行,但是如果我将这个主类的指针传递给另一个视图控制器,它将被执行,但是视图不会像它应该的那样被添加到主视图控制器的子视图中,我不知道为什么。下面是presentWithSuperview方法:
- (void)presentWithSuperview:(UIView *)superview withStopName:stopName;
{
NSLog(@"present w/ superview called.");
[superview addSubview:self.view];
stopNameLabel.text=stopName;
}发布于 2012-01-21 05:47:06
我做了一个小的例子项目,我不能重现你正在经历的问题。在我的最小项目中,我有3个视图控制器: MainViewController、SecondViewController和ThirdViewController。我将粘贴下面的相关方法,请检查您的项目和此示例之间的差异,这也可能是一个好主意,以张贴更多的代码。
MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
thirdViewController.mainViewController = self;
[thirdViewController showDialogIndirect];
}
-(void)showDialog {
if (secondViewController == nil)
secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil WithStop:@"CLAS"];
if (secondViewController)
[secondViewController presentWithSuperview:self.view withStopName:@"Evan Kimia"];
}SecondViewController
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil WithStop:(NSString *)stopString {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
// init here
}
return self;
}
-(void)presentWithSuperview:(UIView *)superView withStopName:(NSString *)stopName {
NSLog(@"present %@ with superview %@ and stopName %@", self, superView, stopName);
self.view.backgroundColor = [UIColor redColor];
[superView addSubview:self.view];
}ThirdViewController
-(void) showDialogIndirect {
[self.mainViewController showDialog];
}https://stackoverflow.com/questions/8921550
复制相似问题