I have a simple addView problem that is driving me nuts, I know I am overlooking something simple, perhaps another set of eyes can help.
I have a Nib with a view that has a class identity set to TestView
In my view controller, I use the following code:
CGRect myRect = CGRectMake(0, 0, 320,240);
TestView *myTest = [[TestView alloc] initWithFrame:myRect];
[self.view addSubview:myTest];
I have a NSLog in the TestView class's initWithFrame that fires when the above code is executed, but the view doesn't appear in 开发者_如何学Gothe view controllers view.
Thanks for your help.
Did you set the File's Owner object in your nib to be of the TestViewController class? If you're creating the view manually, you don't need to set the class identity of the view in the nib, but you need to set the class identity of the view controller in the nib to be your view controller's class.
If TestView
is a view controller, then try doing it this way:
TestView *myTest = [[TestView alloc] initWithNibName:@"TestView" bundle:nil];
myTest.view.frame = CGRectMake(0, 0, 320,240);
[self.view addSubview:myTest.view];
精彩评论