2016-03-17 53 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