Как я могу создать несколько видов на вид - PullRequest
0 голосов
/ 11 сентября 2011

У меня есть 2 класса с

  1. классом view1. (Из создания проекта с помощью приложения на основе вида, серого на заднем плане)
  2. класс view2. (Из подкласса add file uiviewcontroller дляview1, view2, view3 и view4)

в классе view1 я создаю 4 переменную uiview v1, v2, v3, v4 и связываю ее с видом 1, видом 2, видом 3 и видом 4

в viewdidload для view1

i code

view2 *sub =[[view2 alloc] initWithNibName:@"view2" bundle:nil];
self.v1 = sub.view; (v1,v2,v3,v4 is view that i draw by interface builder on self.view)

но при запуске view2, который я создаю, не появилось;

как я могу заставить его появиться.

view1 http://postimage.org/image/2mqhcxb1g/

view2 http://postimage.org/image/2mqj0gnj8/

спасибо

Ответы [ 2 ]

2 голосов
/ 11 сентября 2011

прямо сейчас вы просто присваиваете это представление переменной, чтобы сделать его видимым, вы должны сделать следующее:

[self.view addSubView:sub];

Это добавит представление к вашему текущему представлению и сделает его видимым.

1 голос
/ 11 сентября 2011

В viewDidLoad появится следующее: (только для view2)

View2 *view2 = [[View2 alloc]
initWithNibName:@"View2" bundle:nil];

[self.view insertSubview:view2.view atIndex:0];
[view2 release];
[super viewDidLoad];

Попробуйте задать кадр для этого, чтобы установить в желаемое положение. И выполните то же самое для других 3 просмотров ...

EDIT

- (void)loadView
{
// Create the main view
CGRect appRect = [[UIScreen mainScreen] applicationFrame];
contentView = [[UIView alloc] initWithFrame:appRect];
contentView.backgroundColor = [UIColor whiteColor];

// Provide support for autorotation and resizing
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view = contentView;
[contentView release];

// reset the origin point for subviews. The new origin is 0,0
appRect.origin = CGPointMake(0.0f, 0.0f);
// Add the subviews, each stepped by 32 pixels on each side
UIView *subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 32.0f, 32.0f)];
subview.backgroundColor = [UIColor lightGrayColor];
[contentView addSubview:subview];
[subview release];

subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 64.0f, 64.0f)];
subview.backgroundColor = [UIColor darkGrayColor];
[contentView addSubview:subview];
[subview release];

subview = [[UIView alloc] initWithFrame:CGRectInset(appRect, 96.0f, 96.0f)];
subview.backgroundColor = [UIColor blackColor];
[contentView addSubview:subview];
[subview release];

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...