【发布时间】:2013-08-19 23:28:33
【问题描述】:
我有一个使用 NSLayoutConstraints 的自定义/子类 UITableViewCell。最左边的 UIImageView 可能会或可能不会填充图像,如果没有,该字段右侧的对象自然会向左移动。在自定义 UITableViewCell 中运行良好,但是我将使用自定义 UITableViewController 填充内容。不幸的是,下面的代码将使用图像填充每一行 cell.dispatchedView ——尽管我被困在没有用任何东西填充行的情况下。
这与 dequeueReusableCellWithIdentifier 有关。想法?
static NSString *CellIdentifier = @"CellIdentifier";
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[NXGActiveUnitsCell class] forCellReuseIdentifier:CellIdentifier];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
NSDictionary *item = [self.model.dataSource objectAtIndex:indexPath.row];
NXGActiveUnitsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if([[[item objectForKey:@"cfs_no"] clean] length] > 0) {
cell.dispatchedView.image = [UIImage imageNamed:@"p.png"];
NSLog(@">>>%@",[item objectForKey:@"cfs_no"] );
} else {
NSLog(@">>> i got nothing so I should not touch this row...");
}
cell.departmentIconView.image = [UIImage imageNamed:@"f.png"];
cell.unitLabel.text = [item valueForKey:@"unit_id"];
return cell;
}
【问题讨论】:
-
您是说您的 if-else 语句的“else”部分从未输入过吗?如果是这样,您需要添加更多代码来显示 self.model 的样子。
-
其实输入的是'else'。当我向下滚动 tableView 时,我看到日志输入 >>> 我什么都没有,所以我不应该触摸这一行......”,但我在该行中看到图像“p.png”。如果我注释掉 if 语句,我在任何行中都看不到“p.png”。我很困惑。
标签: iphone ios objective-c