id 与NSobject的区别:
id会自动判别类型并转换
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//把列表数组中的 对象取出, 该对象有可能是日期对象,也有可能是新闻列表对象
id/ NSObject * object = self . allnewsLists[indexPath.row];
//如果取出的是日期对象, 创建日期cell,并返回日期cell
if ([object isKindOfClass:[Date class]]) {
DateCell *dateCell = [tableView dequeueReusableCellWithIdentifier:@"dateCell" forIndexPath:indexPath];
dateCell.date = object;
return dateCell;
}
//如果取出的是新闻列表对象, 创建列表cell,并返回列表cell
NewsListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"newsListCell" forIndexPath:indexPath];
cell.newsList = object;
return cell;
}