UITableView's reusableTableC

2017-05-11  本文已影响56人  Crazy2015

@implementation UITableView (T)

@end

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ViewController

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 =     (
        "<UITableViewCell: 0x7c3a4af0; frame = (0 88; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c380f20>>",
        "<UITableViewCell: 0x7c3a4290; frame = (0 44; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c3a4420>>",
        "<UITableViewCell: 0x7c39dfd0; frame = (0 0; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c39e300>>"
    );
    其中test为NSMutableDictionary的key.
     (
        "<UITableViewCell: 0x7c3a4af0; frame = (0 88; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c380f20>>",
        "<UITableViewCell: 0x7c3a4290; frame = (0 44; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c3a4420>>",
        "<UITableViewCell: 0x7c39dfd0; frame = (0 0; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x7c39e300>>"
    )
   为键对应的值,数据结构为数组。通过 对比数组中frame可以发现:
数组第一个元素:frame = (0 88; 320 44);
数组第二个元素:frame = (0 44; 320 44);
数组第三个元素:frame = (0 0; 320 44);

最先离开屏幕的元素,最近加入到数组中。同时,从数组中取元素的顺序也是,最先加入数组的元素,最先被取出来。这其实就是**队列**的思想。
同时我们也可以从方法的命名看出来问题:
dequeueReusableCellWithIdentifier:

}
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

上一篇下一篇

猜你喜欢

热点阅读