我正在使用表格视图单元格并在单击单元格中的按钮时添加一个弹出视图。但是当我滚动表格视图视图时,弹出窗口正在从我的单元格中消失。这是我的代码:
- (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) {
}];
}