純代碼使用UITableViewController, iOS 8 下在dequeueReusableCellWithIdentifier: forIndexPath:處Crash , iOS 9+無此問題,已經(jīng)通過代碼進行Cell注冊
Crash_LOG.png
現(xiàn)解決方案:
- 在數(shù)據(jù)源方法中額外添加注冊Cell代碼
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 關(guān)鍵代碼
[tableView registerClass:[JSContactMeCell class] forCellReuseIdentifier:kContactMeReusedIdentifier]; // 新增代碼用于修復(fù)iOS8 Crash
JSContactMeCell *cell = [tableView dequeueReusableCellWithIdentifier:kContactMeReusedIdentifier forIndexPath:indexPath];
return cell;
}
2.iOS 8使用 dequeueReusableCellWithIdentifier方法獲取Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (iOS9) {
JSContactMeCell *cell = [tableView dequeueReusableCellWithIdentifier:kContactMeReusedIdentifier forIndexPath:indexPath];
return cell;
}
JSContactMeCell *cell = [tableView dequeueReusableCellWithIdentifier:kContactMeReusedIdentifier];
if (cell == nil) {
cell = [[JSContactMeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kContactMeReusedIdentifier];
}
return cell;
}