Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更新UITableViewCell子类布局_Ios_Objective C_Cocoa Touch_Uitableview - Fatal编程技术网

Ios 更新UITableViewCell子类布局

Ios 更新UITableViewCell子类布局,ios,objective-c,cocoa-touch,uitableview,Ios,Objective C,Cocoa Touch,Uitableview,如果我有一个UITableViewCellSubclass,它可以根据TypeA或TypeB改变布局 我是否应该有一个init是[UITableViewCellSubclass initWithType:type],并且每当类型更改时,我调用[tableView重新加载RowsatindeXPath:indexPathForUITableViewCellSubclass] 或 我跳过了自定义初始化,实现了-layoutSubviews和-setType:,每当我需要更改单元格的类型时,我都会通过

如果我有一个
UITableViewCellSubclass
,它可以根据
TypeA
TypeB
改变布局

我是否应该有一个init是
[UITableViewCellSubclass initWithType:type]
,并且每当类型更改时,我调用
[tableView重新加载RowsatindeXPath:indexPathForUITableViewCellSubclass]

我跳过了自定义初始化,实现了
-layoutSubviews
-setType:
,每当我需要更改单元格的类型时,我都会通过调用
[tableView cellForRowAtIndexPath:indexPath]
然后调用
[CellSetType:TypeB]
来获得对单元格的引用

- (void)setType:(Type)type {

    if (type == _type) return;
    _type == type;
    [self setNeedsLayout];
}

- (void)layoutSubviews {

    [super layoutSubviews];

    if (self.type == TypeA) {
        CGRect frame = foo;
        thing.frame = frame;
    }

    if (self.type == TypeB) {
        CGRect frame = bar;
        thing.frame = frame;
    }
}

编辑:我应该澄清,类型更改实际上并没有改变很多。只是更改一个指示电池类型的图像。

为什么要经历这些麻烦?为什么不创建两个不同的类并在CFIAP中将正确的类出列呢?如果它们共享很多功能,就让它们从基类继承。我应该澄清,类型更改实际上并没有改变很多。只是更改一个指示单元格类型的图像。我认为子类化在这里更合适,正如上面所建议的那样-您需要将不同的代码挂在某个地方,因此为什么不以整洁的方式进行操作?单元格需要知道绘制/配置/设置特定类型的单元格的类型。我如何在
表格视图:cellforrowatinexpath:
中设置它,这取决于它应该显示
TypeA
还是
TypeB