Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIview的子类调用autorelease导致崩溃_Ios_Objective C_Iphone_Uitableview_Uiview - Fatal编程技术网

Ios UIview的子类调用autorelease导致崩溃

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

如果你投了反对票,请解释原因。 我有一个子类UIView用于tableview节头

@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状态