【发布时间】:2011-08-22 16:06:21
【问题描述】:
我正在构建一个使用自定义 tableView 单元格的应用程序,但我不确定是否正确: 例如,我不太确定 cellOwner...
基本问题是,我在 IB 中定义和连接的所有出口在运行时都为零。 这是我所做的:
- 构建 UITableViewCell (ProductListTableViewCell) 的自定义子类
- 制作了一个笔尖,包含一个 UITableViewCell 作为根元素
- 将单元格的 className 和 owner Type 都设置为 ProductListTableViewCell
- 设置重用标识符
- 然后将几个标签等放在单元格上,并通过拖放生成出口
- 仔细检查所有插座是否正确连接。
然而,出口都是零。 我做错了什么?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ProductListTableViewCell";
ProductListTableViewCell *cell =(ProductListTableViewCell*) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
ProductListTableViewCell *cellOwner = [[ProductListTableViewCell alloc]init];
UINib* nib = [UINib nibWithNibName:@"ProductListTableViewCell" bundle:nil];
cell =(ProductListTableViewCell*) [[nib instantiateWithOwner:cellOwner options:nil]objectAtIndex:0];
}
// all outlets are nil here
【问题讨论】:
-
您是否为表格视图 xib 设置了相同的标识符 ProductListTableViewCell ?
-
是 - 通过 IB 设置相同的标识符
标签: iphone uitableview