Table View上の特定のCellの上下の罫線(セパレート)を削除したいのですが、
下記のコードでは全てのCellのセパレートが消えてしまいます。
特定のCellのみセパレートを削除する方法はないのでしょうか?
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
宜しくお願いします。
コメントありがとうございます。
ご紹介いただきました方法ですと、全ての境界線が削除されてしまいます。
質問内容がわかりにくくすみませんでした。
やりたかったのは、2セクションのうち2つ目のセクションのセルの境界線を削除したく、fiwaさんご紹介のコードから下記のコードで出来るようになりました。
{
return 2;
}
{
if( section == 0){
return 2;
}else{
return 1;
}
return 1;
}
{
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) { // yes
// セルを作成
cell = UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//cell.separatorInset = UIEdgeInsetsMake(0,10000,0,0);
if(indexPath.section == 0){
if (indexPath.row == 0) {
UIView *line = UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
} else if (indexPath.row == 2 - 1) {
UIView *line = UIView alloc] initWithFrame:CGRectMake(21, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
UIView *lineBottom = UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
lineBottom.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:lineBottom];
//[cell bringSubviewToFront:lineBottom];
}
}
cell.textLabel.text = @"test";
return cell;
}
{
if(indexPath.section == 1){
cell.backgroundColor = [UIColor clearColor];
}
}
最終的には下記のコードで特定のセクション内のセルの境界線を削除できるようになりました。
{
return 2;
}
{
if( section == 0){
return 2;
}else{
return 1;
}
return 1;
}
{
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) { // yes
// セルを作成
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//cell.separatorInset = UIEdgeInsetsMake(0,10000,0,0);
if(indexPath.section == 0){
if (indexPath.row == 0) {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
} else if (indexPath.row == 2 - 1) {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(21, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
UIView *lineBottom = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
lineBottom.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:lineBottom];
//[cell bringSubviewToFront:lineBottom];
}
}
cell.textLabel.text = @"test";
return cell;
}
{
if(indexPath.section == 1){
cell.backgroundColor = [UIColor clearColor];
}
}
コメントありがとうございます。
ご紹介いただきました方法ですと、全ての境界線が削除されてしまいます。
質問内容がわかりにくくすみませんでした。
やりたかったのは、2セクションのうち2つ目のセクションのセルの境界線を削除したく、fiwaさんご紹介のコードから下記のコードで出来るようになりました。
{
return 2;
}
{
if( section == 0){
return 2;
}else{
return 1;
}
return 1;
}
{
NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) { // yes
// セルを作成
cell = UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
//cell.separatorInset = UIEdgeInsetsMake(0,10000,0,0);
if(indexPath.section == 0){
if (indexPath.row == 0) {
UIView *line = UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
} else if (indexPath.row == 2 - 1) {
UIView *line = UIView alloc] initWithFrame:CGRectMake(21, 0, 320, 1)];
line.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:line];
//[cell bringSubviewToFront:line];
UIView *lineBottom = UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
lineBottom.backgroundColor = [UIColor colorWithRed:0.82f green:0.82f blue:0.82f alpha:1.0f];
[cell addSubview:lineBottom];
//[cell bringSubviewToFront:lineBottom];
}
}
cell.textLabel.text = @"test";
return cell;
}
{
2014/02/09 10:38:22if(indexPath.section == 1){
cell.backgroundColor = [UIColor clearColor];
}
}