2016-03-17 50 views
1

我的代码:实例变量[(超级或自​​)INIT ...]

- (instancetype)initWithSender:(UIView*)sender withSuperView:(UIView*)superView withItems:(NSMutableArray*)items 
{ 
    self = [CustomDropdownView loadInstanceFromNibWithiPad:NO]; 
    if (self) { 
     self.frame = CGRectZero; 

     [self.layer setBorderColor:[UIColor lightGrayColor].CGColor]; 
     [self.layer setBorderWidth:1.0]; 

     CGRect positionInSuper = [superView convertRect:sender.frame fromView:sender.superview]; 
     float height = superView.frame.size.height - positionInSuper.origin.y; 
     if (height > 200.0) { 
//   height = 200.0; 
     } 

     [superView addSubview:self]; 
     self.translatesAutoresizingMaskIntoConstraints = NO; 

     self.constLeading = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:positionInSuper.origin.x]; 
     self.constTop = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeTop multiplier:1.0 constant:positionInSuper.origin.y + sender.frame.size.height]; 

     self.constWidth = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:sender.frame.size.width]; 
     self.constHeight = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:0]; 

     [superView addConstraints:@[self.constLeading, self.constTop]]; 
     [self addConstraints:@[self.constWidth, self.constHeight]]; 

     [self layoutIfNeeded]; 

     self.arrItems = [[NSMutableArray alloc]initWithArray:items]; 

     [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([DropDownTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([DropDownTableViewCell class])]; 

     [self.tableView reloadData]; 
    } 
    return self; 
} 
+0

这是一个静态分析器的警告?内存泄漏在哪里发挥作用?请在问题中包含所有相关信息。你的问题是,在初始化程序中将'self'重新赋值给除''self'''或'[super init]'的调用结果之外的东西是不好的。 – dan

+0

我从产品运行分析器 - >分析 – Nik

回答

0

第一行

self = [CustomDropdownView loadInstanceFromNibWithiPad:NO]; 

是非常有问题的。您应该只分配另一个init方法的结果,通常是[super init]。将其更改为类方法。

顺便说一下,这就是错误信息所说的。

+0

如果我使用self = [super init];那么它的工作原理,但现在我有一个问题,然后我可以如何分配[CustomDropdownView loadInstanceFromNibWithiPad:NO]方法的结果? – Nik