0

我正在制作一个 iphone 应用程序,在该应用程序中我在第一个单元格中创建输入字段,所以问题是当应用程序加载时,它会在 tableView 中的文本字段下方显示一行我想删除该行,如果我们添加新行那么它不显示行但是当行为一时,它显示行。我还附上了应用程序的屏幕截图。

在此处输入图像描述

 -(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,2,248,30)];



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

    tagInputField.backgroundColor=[UIColor whiteColor];

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





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



    //[tagInputField setBorderStyle:UITextBorderStyleRoundedRect];






    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 setBorderStyle:UITextBorderStyleNone];

    [tagInputField setFrame:CGRectMake(8,2,240,32)];

    tableView.backgroundColor=[UIColor whiteColor];







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

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






    return cell;
}
4

1 回答 1

0

如果您不使用它,您可以做的是在页脚中添加一个空视图。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];

    return view;
}

另一种选择是使用 UITableViewStyleGrouped 样式。

-丛

于 2013-10-26T13:19:37.340 回答