在UILabel上调用setBackgroundColor会导致崩溃

时间:2014-04-07 21:20:08

标签: ios objective-c exc-bad-access

好的,所以我一直在拔头发,试着在我的代码中找到这个问题的原因,然后我把它缩小到一行。问题是,它没有任何意义。我创建了一个UIViewController并将此代码放在init方法

- (id)init
{
    [super init];

    [self.view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];

    iCodeAppDelegate*appDelegate = [[UIApplication sharedApplication] delegate];
    UIWindow*window = appDelegate.window;

    int headerY = appDelegate.rootNavigator.navigationBar.bounds.size.height;// + [UIApplication sharedApplication].statusBarFrame.size.height;

    //project options table
    int tableOffsetY = 250;
    UITableView* projectOptions = [[UITableView alloc] initWithFrame:CGRectMake(0, headerY+tableOffsetY, window.bounds.size.width, window.bounds.size.height-(headerY+tableOffsetY)) style:UITableViewStyleGrouped];
    projectOptions.delegate = self;
    projectOptions.dataSource = self;
    projectOptions.scrollEnabled = NO;

    [self.view addSubview:projectOptions];
    [projectOptions release];

    //xcode logo image
    int centerX = window.bounds.size.width/2;
    int logoOffsetY = 8;
    int logoScale = 200;
    UIImage* xcodeLogo = [UIImage imageNamed:@"Images/xcode_logo.png"];

    UIImageView* xcodeLogoView = [[UIImageView alloc] initWithFrame:CGRectMake(centerX-(logoScale/2), headerY+logoOffsetY, logoScale, logoScale)];
    [xcodeLogoView setImage:xcodeLogo];
    //[xcodeLogoView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];

    [self.view addSubview:xcodeLogoView];
    [xcodeLogo release];
    [xcodeLogoView release];

    //"Welcome to Minicode" text
    int welcomeLabelHeight = 50;
    UILabel*welcomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headerY+logoScale+8, window.bounds.size.width, welcomeLabelHeight)];
    [welcomeLabel setText:@"Welcome to miniCode"];
    [welcomeLabel setTextColor:[UIColor darkGrayColor]];
    [welcomeLabel setTextAlignment:UITextAlignmentCenter];
    [welcomeLabel setBackgroundColor:[UIColor clearColor]];
    [welcomeLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 24.0f]];
    [self.view addSubview:welcomeLabel];
    [welcomeLabel release];

    return self;
}

问题在于这个特定的界限:

[welcomeLabel setBackgroundColor:[UIColor clearColor]];

如果我发表评论,代码工作正常,除了标签后面有一个大白框。我在互联网上搜索过,似乎只有一个人遇到过类似的问题。 The solution doesn't seem to have any sort of application to my code, however.

0 个答案:

没有答案