2013-02-25 2 views
0

I привышные UIViewIOS: UIView не отображается

Согласовать
@implementation PaiLifePageDetail 

@synthesize pageIndex = _pageIndex; 

#define MARGINTOTOP 200.0 
#define MARGINTOLEFT 20.0 
#define WIDTH 120.0 
#define HEIGHT 150.0 


- (id) initWithDataSource : (NSArray *) dataSource 
{ 
self = [super init]; 
if (self) 
{ 
    if (dataSource) 
    { 
     for (PaiLifeCustomImageView *imageView in dataSource) 
     { 
      //page 1 line 1 
      if (_pageIndex == 1) 
      { 
       if ([imageView.location isEqualToString:@"r11"]) 
       { 
        imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP, WIDTH, HEIGHT * 2); 
        [self addSubview:imageView]; 
       } 
       else if ([imageView.location isEqualToString:@"r12"]) 
       { 
        imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP, WIDTH, HEIGHT); 
        [self addSubview:imageView]; 
       } 
      } 
      //not page 1 line 1 
      else 
      { 
       if ([imageView.location isEqualToString:@"r11"]) 
       { 
        imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP, WIDTH, HEIGHT); 
        [self addSubview:imageView]; 
       } 
       else if ([imageView.location isEqualToString:@"r12"]) 
       { 
        imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP, WIDTH, HEIGHT); 
        [self addSubview:imageView]; 
       } 
       else if ([imageView.location isEqualToString:@"r13"]) 
       { 
        imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP, WIDTH, HEIGHT); 
        [self addSubview:imageView]; 
       } 
      } 

      // line 2 
      if ([imageView.location isEqualToString:@"r21"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 
      else if ([imageView.location isEqualToString:@"r22"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 
      else if ([imageView.location isEqualToString:@"r23"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP + HEIGHT + 20, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 

      // line 3 
      if ([imageView.location isEqualToString:@"r31"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 
      else if ([imageView.location isEqualToString:@"r32"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT + WIDTH + 20, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 
      else if ([imageView.location isEqualToString:@"r33"]) 
      { 
       imageView.frame = CGRectMake(MARGINTOLEFT + (WIDTH + 20) * 2, MARGINTOTOP + (HEIGHT + 20) * 2, WIDTH, HEIGHT); 
       [self addSubview:imageView]; 
      } 

     } 
    } 
} 
[self setNeedsDisplay]; 
return self; 
} 
@end 

И это мой взгляд

implementation PaiLifeViewController 

@synthesize detail = _detail; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
UIImage *i = [UIImage imageNamed:@"menu_patcode_normal"]; 
PaiLifeCustomImageView *c1 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c1.location = @"r11"; 
PaiLifeCustomImageView *c2 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c2.location = @"r12"; 
PaiLifeCustomImageView *c4 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c4.location = @"r21"; 
PaiLifeCustomImageView *c5 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c5.location = @"r22"; 
PaiLifeCustomImageView *c6 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c6.location = @"r23"; 
PaiLifeCustomImageView *c7 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c7.location = @"r31"; 
PaiLifeCustomImageView *c8 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c8.location = @"r32"; 
PaiLifeCustomImageView *c9 = [[PaiLifeCustomImageView alloc] initWithImage:i]; 
c9.location = @"r33"; 

NSArray *c = [[NSArray alloc] initWithObjects:c1,c2,c4,c5,c6,c7,c8,c9, nil]; 

//PaiLifePageDetail *pagec 
_detail.pageIndex = 1; 
_detail= [[PaiLifePageDetail alloc] initWithDataSource:c]; 
[_detail awakeFromNib]; 
} 
@end 

Но это не отображается, я не знаю, почему, мне помочь с этим. Спасибо.

+0

Кажется, что вы никогда не добавить свой взгляд на ваш контроллер представления, не так ли? – Matthias

+0

@Matthias Я добавляю свое представление к контроллеру своего представления в IB. – jxdwinter

+0

Ну, в соответствии с вашим кодом ваш объект 'detail' создается в' viewDidLoad', т. Е. Для опоздания для автоматизации NIB. Если вы хотите загрузить пользовательский вид из NIB, вам необходимо переопределить 'initWithCoder:', c.f. [Руководство Apple] (http://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW23). – Matthias

ответ

Смежные вопросы