Question

The following works fine in 6.1 but the app crashes in 5.1...

weeklyHeaderViewController =[[WeeklyHeaderViewController alloc] init];
[self.view addSubview:weeklyHeaderViewController.view];

This is an iPad app and the view is 939x31 .xib containing 7 UILabel pairs. The controller'r viewDidLoad method inserts a 4x30 image seperator between the 7 pairs then moves the view into position at the bottom of the screen.

I can trace it through the initWithNibName's so it appears to be alloc ining fine. It crashes with at the addSubview and never gets to the viewDidLoad method.

Is there is something I should here that I am missing with regard to 5.1?

Any suggestions would be appreciated.

Thanks,

John

//  WeeklyHeaderViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) { 

    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    CGRect myImageRect = CGRectMake(131, 0, 4, 30);
    UIImageView *image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    [self.view addSubview:image];
    [image release];

    myImageRect = CGRectMake(266, 0, 4, 30);
    image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    self.view addSubview:image];
    [image release];

    myImageRect = CGRectMake(400, 0, 4, 30);
    image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    [self.view addSubview:image];
    [image release];

    myImageRect = CGRectMake(535, 0, 4, 30);
    image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    [self.view addSubview:image];
    [image release];

    myImageRect = CGRectMake(670, 0, 4, 30);
    image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    [self.view addSubview:image];
    [image release];

    myImageRect = CGRectMake(804, 0, 4, 30);
    image = [[UIImageView alloc] initWithFrame:myImageRect];
    [image setImage:[UIImage imageNamed:@"weeklyDaySeparator.png"]];
    [self.view addSubview:image];
    [image release];

    self.view.frame = CGRectMake(74, 687-14, self.view.frame.size.width, self.view.frame.size.height);

}

Était-ce utile?

La solution

Thanks to iOSBegginer who reminded me to uncheck AutoLayout in my xib.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top