在单元格上隐藏MenuView

时间:2015-12-14 10:14:21

标签: objective-c iphone ios8

我在单元格上有一个按钮单击此按钮我想打开一个视图,工作正常。现在的问题是,当我们点击下一个单元格按钮时,我之前的视图并没有隐藏。 这是我正在尝试两种方式,但不是工作。请帮忙。

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *simpleTableIdentifier = @"CustumCellTableViewCell";

            CustumCellTableViewCell *cell = (CustumCellTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
            if (cell == nil)
            {
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustumCellTableViewCell" owner:self options:nil];
                cell = [nib objectAtIndex:0];
            }

             cell.touchButton.tag =indexPath.row;
            [cell.touchButton addTarget:self action:@selector(menuButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            cell.menuView.hidden = YES;


            return cell;
        }



        - (void) menuButtonClick:(id) sender

        {

            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
                CustumCellTableViewCell *cell=(CustumCellTableViewCell *)[table cellForRowAtIndexPath: indexPath];

            if (cell.menuView.hidden) {
                cell.menuView.hidden = NO;
            } else {
                cell.menuView.hidden = YES;
            }
    1 method
    for ( CustumCellTableViewCell *cell1 in table.visibleCells ) {

            NSLog(@"%@",cell1);
            if (cell1 != cell) {
                cell.menuView.hidden = YES;
            }

        }

2 method

for (NSIndexPath *indexpaths in  [table indexPathsForVisibleRows] ) {

        if (indexpaths == indexPath) {

            cell.menuView.hidden = NO;
        }
        else
        {
           cell.menuView.hidden = YES;
        }


    }


         }

3 个答案:

答案 0 :(得分:0)

您正在使用当前选定的单元格。如果要隐藏最后选择的单元格菜单,则必须隐藏最后选择的单元格索引

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lastSelectedCell inSection:0];
        CustumCellTableViewCell *cell=(CustumCellTableViewCell *)[table cellForRowAtIndexPath: indexPath];
cell.menuView.hidden = YES;

/*
 your code goes here
*/

lastSelectedCell = [sender tag];

答案 1 :(得分:0)

    [for ( CustumCellTableViewCell *cell1 in \[table visibleCells\] ) {


            if (cell1 != cell) {
                cell1.menuView.hidden = YES;
            }
            else
            {
                cell1.menuView.hidden = NO;
            }

        }][1]


  [1]: http://

答案 2 :(得分:0)

你可以用indexPath.row添加cell标签,并比较cell.tag是否等于[sender tag]。还要检查发件人标签值是否正确。

   - (void) menuButtonClick:(id) sender
    {

    [table reloadData];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];

    CustumCellTableViewCell *cell=(CustumCellTableViewCell *)[table cellForRowAtIndexPath: indexPath];

    if(cell.tag==[sender tag]){

          cell.menuView.hidden = NO;
     } else {

          cell.menuView.hidden = YES;
     }

  }