【问题标题】:how to remove the line below the tableView cell in iphone如何删除iphone中tableView单元格下方的行
【发布时间】:2013-10-25 11:42:31
【问题描述】:

我有 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;
    }

【问题讨论】:

  • 为表格视图设置分隔符样式为无
  • 请检查您在 tableView 上的分隔符,并请创建 UITableViewCell 的子类,因为我不想这么说,但这不是好的代码。你删除然后添加你的文本文件的想法会让我今晚不睡觉=p。

标签: ios iphone


【解决方案1】:

更新:

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];

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-17
        • 1970-01-01
        相关资源
        最近更新 更多