獲取一個復(fù)用的Cell有兩種方法:
[tableView dequeueReusableCellWithIdentifier:]
必須要對獲取到的Cell進(jìn)行非空判斷,如果為空就需要自己定義一個cell.
[tableView dequeueReusableCellWithIdentifier: forIndexPath:];
使用之前必須要對cell進(jìn)行注冊。如果注冊以后,可以不進(jìn)行非空判斷。
注冊cell有三種方法:
1.使用xib進(jìn)行注冊
self.tableView registerNib: forCellReuseIdentifier:
//如果使用的是xib進(jìn)行的注冊,創(chuàng)建cell的時候,就會調(diào)用? [NSBundle mainBundle]loadNibName:
2.使用class類來進(jìn)行注冊
[self.tableView registerClass:[HMHeroCell class] forCellReuseIdentifier:cellID];
//如果使用的是class進(jìn)行的注冊,創(chuàng)建cell的時候,會調(diào)用? [class alloc]initWithStyle:defautl樣式 reuseIdentifier
3.關(guān)聯(lián)一個storyboard里的原型cell(prototypeCell)
//如果使用的是storyboard進(jìn)行的注冊,創(chuàng)建cell的時候,會直接加載storyboard里的原型cell.
//設(shè)置Cell右側(cè)的箭頭
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//可以給cell右側(cè)設(shè)置一個accessoryView.
cell.accessoryView = [[UISwitch alloc]init];