Cod*_*nts 13 iphone uitableview
我知道我可以将UITableView属性separatorStyle更改为UITableViewCellSeparatorStyleNone或UITableViewCellSeparatorStyleSingleLine,以便以一种方式更改TableView中的所有单元格.
我感兴趣的是有一些单细胞分离器和一些细胞没有.这可能吗?
Mik*_*ter 17
您最好的选择可能是将表格设置separatorStyle
为UITableViewCellSeparatorStyleNone
并tableView:cellForRowAtIndexPath:
在您需要时手动添加/绘制一条线(可能在中).
根据迈克的建议,这就是我所做的.
在tableView:cellForRowAtIndexPath中:
...
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Drawing our own separatorLine here because I need to turn it off for the
// last row. I can only do that on the tableView and on on specific cells.
// The y position below has to be 1 less than the cell height to keep it from
// disappearing when the tableView is scrolled.
UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
separatorLine.tag = 4;
[cell.contentView addSubview:separatorLine];
[separatorLine release];
}
// Setup default cell setttings.
...
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
...
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
...
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad中:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Run Code Online (Sandbox Code Playgroud)
这很适合我.
cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);
Run Code Online (Sandbox Code Playgroud)
所有这一切都是将线的左侧和右侧的插图推到死点,即160,这使得它不可见.
然后你可以通过indexPath.row控制哪些单元格应用它;
self.separatorInset = UIEdgeInsetsMake(0, CGRectGetWidth(self.frame)/2, 0, CGRectGetWidth(self.frame)/2);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15300 次 |
最近记录: |