如何删除iphone中tableView单元格下面的行

时间:2013-10-25 11:42:32

标签: ios iphone

我有iphone应用程序我在其中添加tableView和tableView单元格我正在添加文本字段但问题是它显示在tableView中textfiled下面的行,如此处附带的图像所示是我的代码。

enter image description 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;
    }

3 个答案:

答案 0 :(得分:2)

<强>更新

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

2)设置SeparatorColor的属性,如:

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

3)删除seprator的其他简单方法是将自定义seprator添加到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];

答案 1 :(得分:1)

它可以来自xib。将分隔符设置为无,如下面的屏幕截图所示。希望它会有所帮助。谢谢 Tableview from xib

答案 2 :(得分:0)

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