Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView空单元格的自定义分隔符_Iphone_Ios_Uitableview_Uiscrollview - Fatal编程技术网

Iphone UITableView空单元格的自定义分隔符

Iphone UITableView空单元格的自定义分隔符,iphone,ios,uitableview,uiscrollview,Iphone,Ios,Uitableview,Uiscrollview,我想制作一个应该使用技术的样本,你们可以在提醒、iBook、便笺应用程序中看到。 正如您在提醒应用程序中所看到的,分隔符如下所示: 提醒具有点线分隔符。 iBook有书架分隔器。 所以问题是如何像示例应用程序中那样定制分隔符?即使表格视图中未设置数据,也应绘制分隔符为什么不尝试使用节标题为您提供自定义视图?在.m文件中,尝试: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; { return [_ce

我想制作一个应该使用技术的样本,你们可以在提醒、iBook、便笺应用程序中看到。


正如您在提醒应用程序中所看到的,分隔符如下所示:

提醒具有点线分隔符。
iBook有书架分隔器。

所以问题是如何像示例应用程序中那样定制分隔符?即使表格视图中未设置数据,也应绘制分隔符

为什么不尝试使用节标题为您提供自定义视图?在.m文件中,尝试:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; {
  return [_cellArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; {
  return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; {
  CustomView * customView = [[CustomView alloc] init]; // This view is the custom view you want, like the dotted lines for example.
  return customView;
}

至于总是让它显示,您可能需要添加空白单元格以获得此外观。希望有帮助

基本上,您实现了

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
在该方法中,您可以实现对最上面、最下面和所有其他单元格的识别,并适当地设置它们的包圆形图像

在书架式桌面视图的情况下,我将实现最顶部的桌面视图,底部有一个书架,顶部有一个书架。对于所有其他人,我将实现一个标准外观的中间架子,对于最底层的人,我将实现一个更底层的架子

因此,要实现我在CellForRoataIndeXPath方法中所说的,像这样的代码应该可以工作

UIImage * rowBackground;
UIImage * selectionBackground;

if( 0 == [indexPath row] ){
    rowBackground       = [UIImage imageNamed:@"listBackingTop.png"];
    selectionBackground = [UIImage imageNamed:@"listBackingTopSelected.png"];
}else if( 217 == [indexPath row] ){
    rowBackground       = [UIImage imageNamed:@"listBackingBottom.png"];
    selectionBackground = [UIImage imageNamed:@"listBackingBottomSelected.png"];
}else{      
    rowBackground       = [UIImage imageNamed:@"listBackingMiddle.png"];
    selectionBackground = [UIImage imageNamed:@"listBackingMiddleSelected.png"];
}

((UIImageView *)cell.backgroundView).image         = rowBackground;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
在我上面的例子中,217是我的最大行数

请记住,您可以控制有多少行,因此如果需要,可以为每一行实现不同的备份。我做过桌面视图,其中蓝色表示偶数行,橙色表示奇数行,顶部和底部仍然是圆形,单元格之间是方形

下面是一些用于更复杂设置的代码,其中有橙色和蓝色,顶部和底部单元格与中间单元格不同。还有一个关于细胞的更动态的例子

UIImage * rowBackground;
UIImage * selectionBackground;
UIImage * accessoryImage;
UIImage * backingImage;

if( 0 == [indexPath row] ){
    rowBackground       = [UIImage imageNamed:@"listTop.png"];
    selectionBackground = [UIImage imageNamed:@"listTopDown.png"];
}else if( (amountRows - 1) == [indexPath row] ){

    if( 0 == ([indexPath row] % 2) ){
        rowBackground       = [UIImage imageNamed:@"listBottomOrange.png"];
        selectionBackground = [UIImage imageNamed:@"listBottomOrangeDown.png"];
    }else{
        rowBackground       = [UIImage imageNamed:@"listBottomBlue.png"];
        selectionBackground = [UIImage imageNamed:@"listBottomBlueDown.png"];
    }

}else{      
    if( 0 == ([indexPath row] % 2) ){
        rowBackground       = [UIImage imageNamed:@"listMiddleOrange.png"];
        selectionBackground = [UIImage imageNamed:@"listMiddleOrangeDown.png"];
    }else{
        rowBackground       = [UIImage imageNamed:@"listMiddleBlue.png"];
        selectionBackground = [UIImage imageNamed:@"listMiddleBlueDown.png"];
    }
}

accessoryImage = [UIImage imageNamed:@"arrow.png"];
accessory.image = accessoryImage;

backingImage = [UIImage imageNamed:@"imageBacking.png"];
imageBack.image = backingImage;

((UIImageView *)cell.backgroundView).image         = rowBackground;
cell.backgroundView.alpha                          = 0.9;
((UIImageView *)cell.selectedBackgroundView).image = selectionBackground;
cell.selectedBackgroundView.alpha                  = 0.5;

我想我想表达的主要观点是,不要将分隔符从单元格中分离出来,让它成为单元格背景的一部分。

需要添加
UIView
with
backgroundColor
作为
patternWithColor:[“使用自定义分隔符的图像”]
以下
UITableView
contentSize

CGSize size = _tableView.contentSize;
UIView *footerImageView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, size.height + 50, 320.0f, 600.0f)];
footerImageView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Shelf.png"]];
[_tableView addSubview:footerImageView];

在这种情况下,它将真正归结为自定义图像和自定义UITableView。我认为下面的链接不会有帮助。我找到了一些想法,但不知道如何实施。你可以在答案[这里]()中找到想法分割器是图像基础的一部分!!!我做过类似的UITableView。你能给我发一个示例代码吗?分隔符是否会显示为没有数据?“即使没有为表视图设置数据,分隔符也应该是绘图的。”我的意思是,当您打开iBook或提醒时,它们的无内容和分隔符仍然是绘图的。这就是我上面所说的。只需在
cellForRowAtIndexPath:
方法和普通单元格中实现空白单元格,即使没有数据,也会绘制分隔符。