fighting~iOS Developer程序员

多个Cell共用一个控件导致死循环和内存暴涨

2016-05-06  本文已影响409人  xshenpan

新手

/**
   *  其中有一部分是在storyboard中完成的
   */

@interface XSPTableViewController ()
//每个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个Cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
//返回每个cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XSPTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.accessoryView = self.arrowView;
    return cell;
}
@end

*** 然后,他就死掉了!!! 内存暴涨 ***
如图:

Snip20160506_2.png Snip20160506_1.png
  @implementation XSPTableViewCell
- (void)layoutSubviews
{
    [super layoutSubviews];
    NSLog(@"%s", __func__);
}
@end

还请各位大神解释下原因啊!搞不懂为什么。新手一枚,大神勿喷!

上一篇下一篇

猜你喜欢

热点阅读