0

我有 iphone 应用程序,我在其中添加 tableView 并在 tableView 单元格内添加文本字段,但问题是它在 tableView 中的文本文件下方显示行,如附图所示,这里是我的代码。

在此处输入图像描述

我想删除输入字段下方的行 Enter Tag Here

-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  if(!cell) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
   // cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"tabelsales.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
    //cell.backgroundColor = [UIColor clearColor];
   }

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



  tableView.backgroundView=nil;


   if(indexPath.section==0){
    tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,1,249,28)];



    tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    tagInputField.textAlignment=UITextAlignmentLeft;

    tagInputField.backgroundColor=[UIColor whiteColor];

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


    tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8];
    [tagInputField setText:@"Enter tag here "];
    tagInputField.textColor =[UIColor grayColor];
    [cell addSubview:tagInputField];
    if(tagArray.count >0)
    {

        [tagInputField setBorderStyle:UITextBorderStyleNone];





    }
    else {
          [tagInputField setBorderStyle:UITextBorderStyleRoundedRect];





    }


    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(8,1,240,30)];

    tableView.backgroundColor=[UIColor whiteColor];







    [publishButton setFrame:CGRectMake(40,560,250, 50)];

    [descriptionTextImageView setFrame:CGRectMake(48,450,250,90)];






    return cell;
    }
4

3 回答 3

2

更新:

1)将tableview separatorStyle的属性设置为UITableViewCellSeparatorStyleNone。

2)设置 SeparatorColor 的属性,如:

   [self.tableView setSeparatorColor:[UIColor clearColor]];

3)删除分隔符的其他简单方法是将自定义分隔符添加到 1px 高度的简单 UIView:

  UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
  separatorLineView.backgroundColor = [UIColor clearColor]; // as per your requirement set color.
  [cell.contentView addSubview:separatorLineView];

4)编写tableview的这个委托方法:

 - (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
   { 
       return 0.01f;// here remove your footer
   }

  - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
     {
       // To "clear" the footer view
       return [[UIView new] autorelease];
     }

5)试试这个:

   self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,460) style:UITableViewStylePlain];
   self.tblView.delegate=self;
   self.tblView.dataSource=self;
   [self.view addSubview:self.tblView];

   UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
   v.backgroundColor = [UIColor clearColor];
   [self.tblView setTableHeaderView:v];
   [self.tblView setTableFooterView:v];
   [v release];
于 2013-10-25T11:55:35.707 回答
1

它可以来自xib。将分隔符设置为无,如下图所示。希望它会有所帮助。谢谢 来自xib的表格视图

于 2013-10-25T11:53:57.493 回答
0

您应该将 UITableView 的 separatorStyle 属性设置为 UITableViewCellSeparatorStyleNone。

于 2013-10-25T11:53:50.243 回答