iphone - 自定义 UITableViewCell 中的自定义 UIView

标签 iphone ios uiview uitableview

我想要在子类 UITableViewCell 中有两个自定义(即子类)UIView,如下图所示。这两个 UIView 是同一个子类。

enter image description here

自定义 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/

相关文章:

iOS App store 提交 - 我可以向苹果提交一个facebook测试用户帐户信息吗

ios - "Signing identity"和 "certificate"之间的区别?

ios - 如何映射这些实体之间的关系-Coredata iOS

iphone - 无法访问向其中传递值的 NSMutableDictionary 外部方法

iphone - Web View 中的 YouTube - iPhone

ios - UIPickerView 中中心行的静态 View

iphone - 如何绘制弹出 View 而不是在 iPhone 上使用图像?

ios - TRANSACTION_REFUSED - 交易被拒绝。在 Paypal ios sdk

iphone - 推送或本地通知提醒用户在已保存数据和远程数据之间进行更改

ios - 在 UITableView Swift 的所有部分上方添加 UIView