UITableView's reusableTableCells

@implementation UITableView (T)

  • (NSMutableArray *)reusableCells
    {
    return [self performSelector:@selector(_reusableTableCells)];
    }

@end

@interface ViewController ()

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ViewController

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    [self.view addSubview:self.tableView];

    [self reloadData];

    [self performSelector:@selector(reloadData) withObject:nil afterDelay:.8];
    }

  • (void)reloadData
    {
    NSLog(@"--------------------");
    NSLog(@"before reloadData");
    NSLog(@"%@", [self.tableView valueForKey:@"_reusableTableCells"]);

    [self.tableView reloadData];

    NSLog(@"after reloadData");
    NSLog(@"%@", [self.tableView valueForKey:@"_reusableTableCells"]);
    }

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return 3;
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
    if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"];
    }
    NSLog(@"make cell row:%d", indexPath.row);

    return cell;
    }
    @end

2014-10-17 19:23:09.334 test[52333:4372534] --------------------
2014-10-17 19:23:09.335 test[52333:4372534] before reloadData
2014-10-17 19:23:09.335 test[52333:4372534] (null)
2014-10-17 19:23:09.335 test[52333:4372534] after reloadData
2014-10-17 19:23:09.335 test[52333:4372534] {
}
2014-10-17 19:23:09.344 test[52333:4372534] make cell row:0
2014-10-17 19:23:09.347 test[52333:4372534] make cell row:1
2014-10-17 19:23:09.347 test[52333:4372534] make cell row:2
2014-10-17 19:23:10.136 test[52333:4372534] --------------------
2014-10-17 19:23:10.136 test[52333:4372534] before reloadData
2014-10-17 19:23:10.137 test[52333:4372534] {
}
2014-10-17 19:23:10.137 test[52333:4372534] after reloadData
2014-10-17 19:23:10.137 test[52333:4372534] {

    test =     (
        "
    其中test为NSMutableDictionary的key.
     (
        "

}
2014-10-17 19:23:10.137 test[52333:4372534] make cell row:0
2014-10-17 19:23:10.138 test[52333:4372534] make cell row:1
2014-10-17 19:23:10.138 test[52333:4372534] make cell row:2

参考:
https://gist.github.com/hirohisa/36b61d628a3a1e6866fe
https://github.com/Microsoft/WinObjC/blob/master/Frameworks/UIKit/UITableView.mm

你可能感兴趣的:(UITableView's reusableTableCells)