我有一个具有3个属性的模型类和一个具有三个单元格的tableview,每个视图都有自己的自定义类。
如何正确安装和填充同一型号的三个不同电池?
@interface Movie : NSObject
@property (nonatomic, strong) UIImage *posterImage;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *overview;
@end
@interface MoviePosterCell : UITableViewCell
@property (nonatomic, strong) UIImageView *poster;
@end
@interface MovieTitleCell : UITableViewCell
@property (nonatomic, strong) UILabel *title;
@end
@interface MovieOverviewCell : UITableViewCell
@property (nonatomic, strong) UILabel *overview;
@end
我试图做这样的事情,但是在我看来这是错误的,因为如果我想重新订购或添加新电池,则必须手动安装所有内容。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
MovieOverviewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MovieOverviewCell class]) forIndexPath:indexPath];
cell.poster = self.movie.posterImage;
return cell;
}
if (indexPath.row == 1)
{
MovieTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MovieTitleCell class]) forIndexPath:indexPath];
cell.title = self.movie.title;
return cell;
}
if (indexPath.row == 2)
{
MovieOverviewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MovieOverviewCell class]) forIndexPath:indexPath];
cell.overview = movie.overview;
return cell;
}
return [UITableViewCell new];
}