我有一个名为UICustomLabel的类,它带有一个变量NSMutableString:_text。我创建了很多这样的对象来将内容显示为页面。以下是要创建的代码:
for (int i = 0; i < linesOfFirstPage; i++) //first page is the special case
{
UICustomLabel * _centerLabel =[[UICustomLabel alloc] initWithFrame:CGRectMake(100.0, 555 + 35 * i, 575.0, 35.0)];//create label in follow kPortraitIpadfirstLabelRect area
if (!_isSmallFont) _centerLabel.frame = CGRectMake(100, 505 + 45 * i, 575, 45);
_centerLabel._textColor=kLabelTextColor;
_centerLabel._backgroundColor=kBackgroundColor;
_centerLabel._font=[UIFont systemFontOfSize:isSmallFont?25:32];
[_contentOfPage addObject:_centerLabel];
[self addSubview:_centerLabel];
[_centerLabel release];
}
之后当我想删除页面中的所有标签时:
if (_contentOfPage) { for (int i = 0; i < [_contentOfPage count]; i++) { UICustomLabel * tmp = [_contentOfPage objectAtIndex:i]; [tmp removeFromSuperview]; } [_contentOfPage removeAllObjects]; }
但是当命令[_contentOfPage removeAllObjects]执行时,我收到错误EXC_BAD_ACCESS;当我在UICustomLabel的方法dealloc中拒绝命令[_text release]时,程序运行正常。那是什么原因?