多個(gè)Cell共用一個(gè)控件導(dǎo)致死循環(huán)和內(nèi)存暴漲

新手

  • 在給cell的accessoryView賦值時(shí)發(fā)現(xiàn)每個(gè)輔助視圖都要?jiǎng)?chuàng)建一個(gè)view,每個(gè)view又都相同,然后我就想能不能只創(chuàng)建一次,給每個(gè)cell都賦值同一個(gè)view,于是就有了如下代碼:
/**
   *  其中有一部分是在storyboard中完成的
   */

@interface XSPTableViewController ()
//每個(gè)cell的輔助視圖都為arrowView
@property (nonatomic, strong) UIImageView *arrowView;
@end

@implementation XSPTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
//懶加載
- (UIImageView *)arrowView
{
    if (_arrowView == nil) {
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right"]];
    }
    return _arrowView;
}

#pragma mark - Table view data source
//一共10個(gè)Cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
//返回每個(gè)cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XSPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.accessoryView = self.arrowView;
    return cell;
}
@end

*** 然后,他就死掉了!??! 內(nèi)存暴漲 ***
如圖:

Snip20160506_2.png
  • 但是xcode有沒有觸發(fā)異常,內(nèi)存都占用了400多M,還是沒有報(bào)異常
  • 最后自定義一個(gè)cell,然后重寫了好多方法,發(fā)現(xiàn)程序在layoutSubviews方法中死循環(huán)
Snip20160506_1.png
  • 代碼如下:
  @implementation XSPTableViewCell
- (void)layoutSubviews
{
    [super layoutSubviews];
    NSLog(@"%s", __func__);
}
@end

還請(qǐng)各位大神解釋下原因?。「悴欢疄槭裁?。新手一枚,大神勿噴!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容