gpt4 book ai didi

ios - 使用相同 xib 的多个 UITableViewCell 子类?

转载 作者:可可西里 更新时间:2023-11-01 04:45:18 24 4
gpt4 key购买 nike

如何在多个 UITableViewCell 子类之间共享一个 xib

它们都有相同的 View 界面,​​所以我不想为了更改单元类而多次复制相同的 xib

- (void)viewDidLoad
{
[super viewDidLoad];

[self.tableView registerNib:[UINib nibWithNibName:@"BaseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"BaseCell"];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BaseCell *baseCell = [tableView dequeueReusableCellWithIdentifier:@"BaseCell" forIndexPath:indexPath];

...

我在这里需要的是我的 ChildCell 实例 - 它是 BaseCell 的子类。有什么想法吗?

最佳答案

使用组合而不是继承。保持 BaseCell 类与其在 nib 中的单元格之间的 1-1 关系,为您创建的实现对象添加一个属性,并在将其出队后添加到单元格对象。

关于ios - 使用相同 xib 的多个 UITableViewCell 子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35126520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com