2012-02-07 59 views
0

我有一个带有xib,.h,.m文件的ViewController。现在我想将它显示为另一个viewController中的popUpView。所以我做了这样的...将ViewController显示为PopUpSubview?

Second *view2 = [[Second alloc] initWithNibName:@"Second" bundle:nil]; 
[view2.view setFrame:CGRectMake(20, 20, 280, 400)]; 
{self.view addSubview:view2.view]; 

但这里的问题我能任意设定框架,但的viewController包含一个文本框和按钮。它们不会被添加到视图中的随机位置,就像一些textField出现在添加的视图框中。

一些谷歌搜索后,我发现这一点,但这不足以解决我的问题。

Adding a ViewConroller's View as subview programmatically

怎么解决呢?

+0

你好,你的ViewController做什么?这是一个登录/传递弹出窗口? – TheRonin 2012-02-07 09:50:07

回答

0

看来你正在改变视图的框架在您的视图控制器,但没有处理视图内元素的重新定位。你可以做的是重写视图中的layoutSubviews方法,以便当框架改变文本字段重新定位它们自己时。

您必须创建一个实际的UIView子类将布局文本字段,

@interface SecondView : UIView{ 

} 

@implementation SecondView{ 
    - (void) layoutSubviews{ 
     //self.frame would be to most up-to-date frame that you just set 
    } 
} 

UIViewController中只会创造像这样的观点,

@interface Second : UIViewController{  
} 


@implementation Second{ 
    - (void) loadView{ 
     self.view = [[[SecondView alloc] init] autorelease]; 
    } 
} 
相关问题