0

我有两个单独的按钮,用于分别在 UITableView 中按升序和降序对数组进行排序。

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

     checkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        checkButton.frame = CGRectMake(540, 30, 42, 42);
        [checkButton setBackgroundImage:[[UIImage imageNamed:@"Down Arrow.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
        [checkButton addTarget:self action:@selector(descender:) forControlEvents:UIControlEventTouchUpInside];
        [checkButton setTag:200];
        [cell.contentView addSubview:checkButton];


        checkButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        checkButton1.frame = CGRectMake(600, 30, 42, 42);
        [checkButton1 setBackgroundImage:[[UIImage imageNamed:@"Up Arrow.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
        [checkButton1 addTarget:self action:@selector(ascender:) forControlEvents:UIControlEventTouchUpInside];
        [checkButton1 setTag:100];
        [cell.contentView addSubview:checkButton1];

checkButton = (UIButton *)[cell viewWithTag:200];
        if (indexPath.row == 0 && appDelegate.a == 300)
        {
            checkButton.hidden = NO;
            checkButton1.hidden = YES;
        }

        checkButton1 = (UIButton *)[cell viewWithTag:100];
        if ((lastSectionIndex == indexPath.section && lastRowIndex == indexPath.row ))
        {
            checkButton.hidden = YES;
            checkButton1.hidden = NO;
        }
}

在 cellforrowAtIndexPath 中,我添加了两个用于排序的按钮。现在,当我单击排序按钮时,该排序按钮应该消失并且必须出现完成按钮。我给它如下,

-(void)sortItem:(id)sender
{
         NSLog(@"sort clicked");

         if(appDelegate.a = 300)
         {
               checkButton.hidden = NO;
               checkButton1.hidden = YES;
         }

          self.navigationItem.title = @"Sort Book Shelf";

          sortButton.hidden = YES;
          editButton.hidden = YES;
          doneButton.hidden = NO;

   //    if (appDelegate.b == 400) 
  //    {
 //        checkButton.hidden = NO;
 //        checkButton1.hidden = NO;
 //    }

      [editTable reloadData];
}

接下来,当我单击 SORT 按钮这两个检查按钮时,检查按钮 1 应该出现,当我单击 DONE 按钮时,这两个按钮应该消失。

-(void)doneClick:(id)sender
{
       NSLog(@"Done Clicked");

       if (appDelegate.b == 400) 
       {
            checkButton.hidden = YES;
            checkButton1.hidden = YES;
       }

       self.navigationItem.title = @"Edit Book Shelf";

       sortButton.hidden = NO;
       editButton.hidden = NO;
       doneButton.hidden = YES;
  }

现在,排序功能运行良好。但是当我点击完成按钮时,我的按钮并没有从单元格路径中消失,因为我给出了将按钮放在第一个和最后一个索引上的条件。如何仅在单击完成按钮时隐藏我的两个按钮?提前非常感谢。

4

3 回答 3

0

在询问 SOF 之前先尝试在 google 上搜索,因为它可能是重复的问题

。H

NSIndexPath *selectedIndexPath;

.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //  . . Some Code . . .
    if ( selectedIndexPath.row = indexPath.row &&  selectedIndexPath.section = indexPath.section ) {
        button1.hidden = NO;
        button2.hidden = NO;
    } else {
        button1.hidden = YES;
        button2.hidden = YES;
    }
    //  . . Some Code . . .
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    selectedIndexPath = indexPath;
    [tableView relaodData];
}

如何在uitableviewCell上添加按钮并在下一个单元格选择中删除上一个

于 2013-01-11T09:08:40.187 回答
0

尝试在 doneClick 中调用重新加载数据。

[editTable reloadData];
于 2013-01-11T09:02:22.663 回答
0

给你的button方法块,里面tableView begin and end updates。喜欢

-(void)doneClick:(id)sender
{
   NSLog(@"Done Clicked");
   [tableView beginUpdates];
   if (appDelegate.b == 400) 
   {
        checkButton.hidden = YES;
        checkButton1.hidden = YES;
   }
   [tableView endUpdates];
   self.navigationItem.title = @"Edit Book Shelf";

   sortButton.hidden = NO;
   editButton.hidden = NO;
   doneButton.hidden = YES;
}
于 2013-01-11T09:09:51.260 回答