【发布时间】:2013-06-26 15:55:40
【问题描述】:
我正在向 UITableViewCell 添加边框。下面是代码:
Try-1:
cell.layer.borderWidth = 1;
cell.layer.borderColor = [UIColor redColor].CGColor;
Try-2:
cell.contentView.layer.borderWidth = 1;
cell.contentView.layer.borderColor = [UIColor redColor].CGColor;
这两种方法我都试过了,这是输出。
正如您在图像中发现的那样,两个单元格之间的边框重叠,因为这种颜色比边框单元格更深。
为什么我没有添加表格边框?
- 问题是,我在单个表中使用三个差异自定义单元格,根据数据,正在加载特定单元格
- 因此我无法为整个 uitableview 添加边框颜色或无法在 cellforrowatindexpath 中绘制单元格边框。因为在该方法中,我只检查它是哪种类型的数据,并相应地加载了自定义单元格。
这是我的cellForRowAtIndexPath:
- (UITableViewCell*) getTableViewCellForTraining:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath withTrainingInfo:(TrainingInfoiOS*)trainingInfo
{
BeLearnPlatform& ptr = BeLearnPlatform::GetLearnPlatform();
static NSString *CustomCellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier forIndexPath:indexPath];
cell.courseNameLabel.text = trainingInfo.courseName;
cell.courseStartButton.sectionID = indexPath.section;
cell.courseStartButton.rowID = indexPath.row;
cell.tag=0;
...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = nil;
NSString* dictionaryKey = [self createKeyWithSection:indexPath.section andRow:indexPath.row];
NSObject* dataObject = [tableViewMappig objectForKey:dictionaryKey];
if([dataObject isKindOfClass:[MasterCourse class]])
{
UITableViewCell* cell = [self getTableViewCellForTraining:tableView cellForRowAtIndexPath:indexPath withTrainingInfo:(MasterCourse*)dataObject];
return cell;
}
else if([dataObject isKindOfClass:[ParentCourse class]])
{
UITableViewCell* cell = [self getTableViewCellForParentCourse:tableView cellForRowAtIndexPath:indexPath withTrainingInfo:(ParentCourse*)dataObject];
return cell;
}
请建议我解决这个问题。
【问题讨论】:
-
tableViewCell添加分隔符,tableView添加边框层
-
我做不到。有些单元格的布局与此不同。这些是无边界单元格。所以,我不能在整个表格视图中添加分隔线。
标签: ios uitableview quartz-core