我想要在子类 UITableViewCell 中有两个自定义(即子类)UIView,如下图所示。这两个 UIView 是同一个子类。
自定义 UIView 和 TableViewCell 都有关联的 xib。
我将不胜感激关于解决此问题的最佳方法的建议。我以这种方式加载 TableViewCell。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:NULL];
// CustomCell is an IBOutlet connected to the above nib
cell = BLCustomCell;
}
// configure the cell
}
我想在自定义 View 中设置导出以轻松显示来 self 的数据模型的数据。我需要自定义 View 的 View Controller 吗?我无法为自定义 View 加载 Nib 。 (是的,我意识到我上面的代码没有解决这个问题。)我如何加载它? TableView 的 Controller 是否需要自定义 View 对象的导出?
谢谢!
最佳答案
处理复杂的 UITableViewCell
的最简单方法是创建一个 UITableViewCell
的子类,它有自己的连接到 subview 的 IBOutlet
,然后只需在 cellForRowAtIndexPath:
中设置自定义单元格的属性。还有各种其他方法,但这个方法似乎相当好地分解了问题,并扩展到处理更复杂的情况。
看看 Matt Drance 的 iOS Recipes 一书,它很好地涵盖了这个领域。
关于iphone - 自定义 UITableViewCell 中的自定义 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7690310/