以下内容在6.1中可以正常运行,但应用在5.1中崩溃...

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

这是一个iPad应用程序,视图为939x31 .xib,包含7个UILabel对。 控制器的viewDidLoad方法在7对之间插入一个4x30图像分隔符,然后将视图移动到屏幕底部的位置。

我可以通过initWithNibName跟踪它,因此它似乎是分配良好的。 它在addSubview处崩溃,并且永远不会进入viewDidLoad方法。

在5.1方面我应该缺少什么吗?

任何建议,将不胜感激。

谢谢,

约翰

//  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);

}

===============>>#1 票数:0 已采纳

感谢iOSBegginer提醒我取消选中xib中的AutoLayout。

  ask by user278859 translate from so

未解决问题?本站智能推荐: