Ios UIview的子类调用autorelease导致崩溃
如果你投了反对票,请解释原因。 我有一个子类UIView用于tableview节头Ios UIview的子类调用autorelease导致崩溃,ios,objective-c,iphone,uitableview,uiview,Ios,Objective C,Iphone,Uitableview,Uiview,如果你投了反对票,请解释原因。 我有一个子类UIView用于tableview节头 @interface ContactSectionHeaderView() @property (nonatomic, retain) IBOutlet UILabel *headerTitle; @end @implementation ContactSectionHeaderView - (id)initWithFrame:(CGRect)frame { self = [super initW
@interface ContactSectionHeaderView()
@property (nonatomic, retain) IBOutlet UILabel *headerTitle;
@end
@implementation ContactSectionHeaderView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self){
id rootView = [[self class] viewSizedForDevice];
[rootView setFrame:frame];
self = rootView;
}
return self;
}
+ (id) viewSizedForDevice {
UINib* nib = [self nib];
NSArray * nibObjects = [nib instantiateWithOwner:self options:nil];
NSAssert2(([nibObjects count] > 0) &&
[[nibObjects objectAtIndex:0] isKindOfClass:[self class]],
@"Nib '%@' does not appear to contain a value %@",
[self nibName], NSStringFromClass([self class]));
id rootView = nibObjects[0];
return rootView;
}
+(UINib*)nib {
NSBundle * classBundle = [NSBundle bundleForClass:[self class]];
UINib * nib = [UINib nibWithNibName:[self nibName] bundle:classBundle];
return nib;
}
+ (NSString *)nibName {
return [self viewIdentifier];
}
+ (NSString *)viewIdentifier {
static NSString* _viewIdentifier = @"ContactSectionHeaderView";
_viewIdentifier = NSStringFromClass([self class]);
return _viewIdentifier;
}
-(void)setTitle:(NSString *)title {
self.headerTitle.text = [NSString stringWithFormat:@"%@",title];
}
- (void)dealloc {
self.headerTitle = nil;
[super dealloc];
}
@end
我在-(UIView*)tableView:(UITableView*)tableView view for headerinsection:(NSInteger)节中使用了类似的方法
ContactSectionHeaderView *sectionHeader = [[[ContactSectionHeaderView alloc] initWithFrame:[tableView rectForHeaderInSection:section]] autorelease];
这是导致崩溃的原因。如果我删除自动释放,那么它工作得很好。如何修复崩溃?删除autorelease
。无需使用ARC的保留、释放方法。ARC为您做它您的项目是ARC还是非ARC?您不需要使用自动释放
因为现在一切都是ARC,它是自动完成的,您使用的是石器时代代码。我的项目是非ARC@AshishThakkar@iphonic,是的,这是一个石器时代的项目。@tausun将其转换为ARC,并删除非ARC代码。我的项目处于非ARC状态