問題:調(diào)用 dequeueReusableCellWithIdentifier: forIndexPath: 代碼報carsh
原因:在cellForRowAtIndexPath 方法中穴豫,調(diào)用上述方法四瘫,之前沒有注冊class那槽。
分析:
- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier; // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.
- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered
本質(zhì)上是這兩個方法的區(qū)別:
1躺翻、有indexpath的方法,在使用的時候眷柔,必須調(diào)用registerClass或者registerNib注冊期虾。
2原朝、在cell獲取的地方,有indexpath的方法無需判斷是否為空镶苞。因?yàn)槿绻也坏絚ell喳坠,會自動調(diào)用initWithStyle:withReuseableCellIdentifier 創(chuàng)建新cell。而indexPath的作用就是茂蚓,在返回cell之前壕鹉,會調(diào)用tableview:heightForRowAtIndexPath來確定cell尺寸。