UITableView的cell兩種注冊(cè)方法:
[_tabV registerClass:[testTableViewCell class] forCellReuseIdentifier:@"cellId"];
testTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];
testTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
if (!cell) { cell = [[testTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"]; }
系統(tǒng)推薦使用第2中方法。
創(chuàng)建一次的視圖寫在花括號(hào)里面,第1種方法復(fù)用的時(shí)候需要判斷只需創(chuàng)建一次的視圖在沒在,在的話需要?jiǎng)h除重建,不然會(huì)疊加在一塊兒