新手
- 在給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
*** 然后查乒,他就死掉了!S艟埂玛迄! 內(nèi)存暴漲 ***
如圖:
Snip20160506_2.png
- 但是xcode有沒(méi)有觸發(fā)異常,內(nèi)存都占用了400多M棚亩,還是沒(méi)有報(bào)異常
- 最后自定義一個(gè)cell蓖议,然后重寫了好多方法,發(fā)現(xiàn)程序在layoutSubviews方法中死循環(huán)
Snip20160506_1.png
- 代碼如下:
@implementation XSPTableViewCell
- (void)layoutSubviews
{
[super layoutSubviews];
NSLog(@"%s", __func__);
}
@end