3

私はtableViewの問題を使用しているアプリを持っています.tableViewに1つのレコードがある場合、区切り線は表示されませんが、2つのレコードがある場合は表示されます。

tableView の最初のセルは textField です。これが私が使用しているコードです。

    for (UIView *subView in cell.subviews)
    {
    if (subView.tag == 2 || subView.tag == 22) 
    {
        [subView removeFromSuperview];
    }
    }

   tableView.backgroundView=nil;

   tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

   tableView.separatorInset = UIEdgeInsetsZero;


   if(indexPath.section==0){

   tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,0,248,31)];



    tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    tagInputField.textAlignment=UITextAlignmentLeft;
    tagInputField.backgroundColor=[UIColor whiteColor];

    tagInputField.tag = 2;
    tagInputField.delegate = self;
    tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;


    [tagInputField.layer setCornerRadius:5.0f];
    [tagInputField.layer setMasksToBounds:YES];
    tagInputField.layer.borderWidth = 0.3;
    tagInputField.layer.borderColor = [UIColor darkGrayColor].CGColor;


    tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8];
    [tagInputField setText:@"Enter tag here "];
    tagInputField.textColor =[UIColor grayColor];





    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

    [cell addSubview:tagInputField];






    return cell;



}


if(indexPath.section==1) {
    UIButton *crossButton =[[UIButton alloc]initWithFrame:CGRectMake(228, 8, 18, 18)];
    crossButton.tag = 22; //use a tag value that is not used for any other subview
    //crossButton.backgroundColor = [UIColor purpleColor];
    crossButton.backgroundColor  = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Cross.png"]];
    [cell addSubview:crossButton];
    cell.textLabel.font =[UIFont fontWithName:@"Myriad-Pro" size:8];
    cell.textLabel.textColor =[UIColor grayColor];

    cell.backgroundColor=[UIColor whiteColor];

    cell.textLabel.text =[tagArray objectAtIndex:indexPath.row];
    [crossButton addTarget:self action:@selector(deleteCell:) forControlEvents:UIControlEventTouchUpInside];


    [tagInputField setFrame:CGRectMake(5,0,248,31)];


    tableView.backgroundColor=[UIColor whiteColor];


    [tagInputField.layer setCornerRadius:0.0f];
    [tagInputField.layer setMasksToBounds:YES];


    tagInputField.layer.borderWidth = 0.0;
    tagInputField.layer.borderColor = [UIColor clearColor].CGColor;




    return cell;
}
4

5 に答える 5

5

レコードが1つしかない場合、セパレーターは表示されず、viewDidLoadでtableViewのセパレーターを次のように設定する必要があります

- (void)viewDidLoad
{
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}

いずれにせよ、すべてのセルに独自のセパレーターを表示したい場合は、テーブルセルごとにimageViewまたはsomrthing witchシェアを追加してみてください

UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 1024, 1)];
separatorView.layer.borderColor = [UIColor redColor].CGColor;
separatorView.layer.borderWidth = 1.0;
[cell.contentView addSubview:separatorView];

iPhoneでtableViewセパレーターをカスタマイズする方法

詳しくは....

于 2013-11-12T05:01:21.440 に答える
1

Cell_for_Row_At_Index_path デリゲート メソッドで次のように試してみてください。

[tableView setSeparatorInset:UIEdgeInsetsZero];
    [tableView setSeparatorColor:[UIColor greenColor]];

この行を貼り付けて確認してください。

于 2013-11-12T05:44:46.967 に答える
0

テーブルビューの最後に空のフッターを追加して、セパレーターを表示します。これを行うには、他のテーブルビュー デリゲート関数を使用して、クラスに次のテーブルビュー デリゲート メソッドを実装します。

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.001; }

于 2013-12-24T15:11:07.913 に答える