我附上了一张图片,因为这有点难以解释,我还模拟了我真正想要的样子。我将尝试对其进行解释,以便其他人可能会发现问题。
也许您以前遇到过这个问题并且知道解决办法?
这是我拥有的图像以及我想要的模型:
在左边,我所拥有的是,表格中的项目没有用分隔线分隔,而是用空行单元格分隔。理想情况下,不会显示空单元格,表格会结束,让背景显示出来,表格中的项目在单元格之间会有分隔符。
这是对应的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
NSMutableArray *withoutThing = [NSMutableArray arrayWithArray:self.containerOfLists];
[withoutThing removeObjectAtIndex:indexPath.row];
self.containerOfLists = withoutThing;
[[NSUserDefaults standardUserDefaults] setObject:self.containerOfLists forKey:@"list of lists"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.containerOfLists count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ListCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = self.containerOfLists[indexPath.row];
return cell;
}
最佳答案
好的。
在 Storyboard
中,选择您的 UITableView
,将 Separator
设置为 Single Line
,或者通过以下代码:
[yourTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
在你的代码中,做某处:
[yourTableView setBackgroundColor:[UIColor lightGrayColor]];
或者你想要的灰色。
将此添加到您的数据源方法(与 tableView: cellForRowAtIndexPath
相同级别):
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] init];
}
关于ios - 任何想法如何解决这个奇怪的 uitableview 分隔线格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22078008/