ios - 任何想法如何解决这个奇怪的 uitableview 分隔线格式问题

标签 ios objective-c uitableview ios7

我附上了一张图片,因为这有点难以解释,我还模拟了我真正想要的样子。我将尝试对其进行解释,以便其他人可能会发现问题。

也许您以前遇到过这个问题并且知道解决办法?

这是我拥有的图像以及我想要的模型: enter image description here

在左边,我所拥有的是,表格中的项目没有用分隔线分隔,而是用空行单元格分隔。理想情况下,不会显示空单元格,表格会结束,让背景显示出来,表格中的项目在单元格之间会有分隔符。

这是对应的代码:

- (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/

相关文章:

objective-c - 如何在显示为模态的 uinavcontroller 中添加 View

ios - NSSortDescriptor 按最后一条消息时间戳对对话进行排序

iphone - 连接 nsstring 并排除空值

iphone - 在电影播放器​​上按“完成”后恢复纵向?

ios - 如何反转 AAC 音频文件?

swift - 将 3D Touch 与 Storyboard的 peek 和 pop 结合使用

ios - 不同音频的音量不断重置 - ios swift

objective-c - 为 AFNetworking 的 UIImageView 类别预缓存图像

ios - TableView重新加载数据的麻烦

iphone - 如何从 UITableView 中删除选定的行?