抛转引玉
我们在创建UITableViewCell的时候,经常编写这样的代码。
static NSString *ID = @"XXXcell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
这段代码在cell复用机制时,ID变量前面是用static修饰的。为什么?
我们首先了解一下static关键字用来修饰局部变量的例子:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self test];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"---------- viewWillAppear -------------");
[self test];
}
- (void)viewDidAppear:(BOOL)animated {
[su