Iphone 设置UILabel背景色会导致应用程序崩溃

Iphone 设置UILabel背景色会导致应用程序崩溃,iphone,ios,xcode,uilabel,sigabrt,Iphone,Ios,Xcode,Uilabel,Sigabrt,我有以下代码: UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)] autorelease]; UIImage *theImage = [UIImage imageNamed:@"question mark icon"]; phot

我有以下代码:

UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)] autorelease];
UIImage *theImage = [UIImage imageNamed:@"question mark icon"];
photo.image = theImage;
UIView *new_view = [[UIView alloc] init];
[new_view addSubview:photo];
UILabel *new_label = [[UILabel alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x-145, title_bar.titleView.frame.origin.y-12, 268.0, 22.0)];
[new_label setText:@"gregrgtg"];
[new_label setBackgroundColor:[UIColor clearColor]]; //COMMENTING THIS LINE OUT MAKES IT WORK
[new_view addSubview:new_label];
title_bar.titleView = new_view;
当背景色设置为“清除”时,程序会发出信号。如果我注释掉那一行,除了标签的背景是白色外,效果很好。另外,如果我只是初始化标签而不是用框架初始化它,程序不会崩溃,但是我的标签看不见

UIImageView *photo = [[[UIImageView alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x+130, title_bar.titleView.frame.origin.y-12, 22.0, 22.0)] autorelease];
UIImage *theImage = [UIImage imageNamed:@"question mark icon"];
photo.image = theImage;
UIView *new_view = [[UIView alloc] init];
[new_view addSubview:photo];

title_bar.titleView = new_view;//this line by madhu

UILabel *new_label = [[UILabel alloc] initWithFrame:CGRectMake(title_bar.titleView.frame.origin.x-145, title_bar.titleView.frame.origin.y-12, 268.0, 22.0)];
[new_label setText:@"gregrgtg"];
[new_label setBackgroundColor:[UIColor clearColor]]; //COMMENTING THIS LINE OUT MAKES IT WORK
[new_view addSubview:new_label];
原因:

你至少已经添加了你的标题栏的标题视图,但之前已经将其引用

原因:


您至少添加了标题栏的标题视图,但之前已将其转介。

谢谢,效果不错!如果你不介意的话,你知道它为什么有效吗?我不认为这会有什么不同。谢谢,这很有效!如果你不介意的话,你知道它为什么有效吗?我认为这不会有什么不同。