0

我正在使用表格视图单元格并在单击单元格中的按钮时添加一个弹出视图。但是当我滚动表格视图视图时,弹出窗口正在从我的单元格中消失。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellF
orRowAtIndexPath:(NSIndexPath *)indexPath
{
     NSString *CellIdentifier =[NSString stringWithFormat:@"ArticleCell%d  %d",indexPath.section,indexPath.row];

    __block ArticleCell_iPad *cell = (ArticleCell_iPad *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[ArticleCell_iPad alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];

        [[NSBundle mainBundle] loadNibNamed:@"SynopsysViewSharing" owner:self options:nil];

        cell = [[[ArticleCell_iPad alloc] initWithFrame:CGRectMake(0, 0, kCellWidth_iPad, kCellHeight_iPad)] autorelease];

        __block NSDictionary *currentArticle = [self.articles objectAtIndex:indexPath.section];

         [cell.iconImage loadImageWithURL:[[currentArticle objectForKey:@"sourceLogoImg"]objectForKey:@"text"]];


        [cell.sideButton setBackgroundImage:[UIImage imageNamed:[cellButtonImageArr objectAtIndex:self.selectIndex]]

        [cell.sideButton addTarget:self action:@selector(sideButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

        cell.sideButton.tag = indexPath.section;

        TableViewCellSelectionStyleNone;

   }
   return cell;
}

按钮动作:

 -(IBAction)sideButtonClicked:(UIButton*)sender
 {

    buttonShare=[[[NSBundle mainBundle] loadNibNamed:@"SynopsysViewSharing" owner:self options:nil] lastObject];

    NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:sender.tag];
    ArticleCell_iPad *cellSelected = (ArticleCell_iPad*)[_horizontalTableView cellForRowAtIndexPath:myIP];

    [cellSelected.contentView addSubview:buttonShare];
    buttonShare.alpha = 0.0f;
    buttonShare.tag=500;
    [buttonShare setFrame:CGRectMake(0,600, cellSelected.frame.size.height,55)];

    [UIView animateWithDuration:0.5 animations:^{
    [buttonShare setFrame:CGRectMake(0,cellSelected.frame.size.width-55, cellSelected.frame.size.height,55)];
    buttonShare.alpha = 1.0f;
   } completion:^(BOOL finished) {

   }];
}
4

2 回答 2

0

而是通过编码将按钮共享添加到内容视图,请尝试在情节提要中为原型单元本身添加“按钮共享”,并通过检查隐藏属性使其隐藏。

并在 UITableviewCell 中点击您的按钮,在 sideButtonClicked 中将 buttonshare 的隐藏属性设置为“NO”:

希望能帮助到你 :)

于 2015-07-20T05:48:10.337 回答
0

您的实现中有两个主要错误:

  1. 在您的 中cellForRowAtIndexPath,您需要为给定的 indexPath 初始化单元格,即使它是重用单元格(如果cell != nil)。
  2. 在您的 中sideButtonClicked,不要调用cellForRowAtIndexPath查找单元格。它将创建一个全新的单元格,而不是返回屏幕上的那个。UIButton而是从方法的参数中得出它是哪一行。

查看Apple 的编程指南

于 2016-01-16T13:10:03.847 回答