0

I am using table view cell and adding a pop up view on clicking a button placed in cell .But when I am scrolling the table view view pop is disappearing from my cell. Here is my code:

- (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;
}

Button Action:

 -(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) {

   }];
}
halfer
  • 19,824
  • 17
  • 99
  • 186
RakeshBiswal
  • 59
  • 10

2 Answers2

0

Instead adding the buttonshare to the contentview through coding, pls try adding your 'buttonshare' in storyboard for the prototype cell itself and make it hidden by checking the hidden property.

And tap on for your button in the UITableviewCell make the hidden property of buttonshare to "NO" in sideButtonClicked:

Hope it helps :)

Bhavin Bhadani
  • 22,224
  • 10
  • 78
  • 108
Vikram Parimi
  • 777
  • 6
  • 29
  • i am using custom table view cell ArticleCell_iPad.I cant change it further – RakeshBiswal Jul 20 '15 at 05:50
  • I assume your **ArticleCell_iPad** it's a Custom tableviewCell class which you have subclassed from UItableviewCell. You can add a drag and drop button and create a Iboutllet for the same to perform your actions instead adding to contentview – Vikram Parimi Jul 20 '15 at 06:05
  • I am using horizontal table view . uitableview-horizontal table view cell-Article table view cell 1.- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HorizontalTableCell_iPad *cell = [self.reusableCells objectAtIndex:indexPath.section]; return cell; } 2.with horizontal table view cell for index path i am using article ipad cell – RakeshBiswal Jul 20 '15 at 06:17
  • what do you mean by __HorizontalTableView__ ? – Vikram Parimi Jul 20 '15 at 06:22
  • Within a table view cell i am adding another table view cell is called horizontal table view cell interface HorizontalTableCell_iPad : UITableViewCell and its content i am setting in article ipad cell interface ArticleCell_iPad : UITableViewCell – RakeshBiswal Jul 20 '15 at 06:29
  • u can follow http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2 – RakeshBiswal Jul 20 '15 at 06:31
  • Ok, now i get it. See that was an old approach for creating that sort of user experience. For now you have **UICollectionView** to create the same experience then you struggling with **UItableView**. Collection will have both horizontal and vertical scrolling exactly the same way you needed it You can follow the link to create a **UICollectionView** [link](http://adoptioncurve.net/archives/2012/09/a-simple-uicollectionview-tutorial/) – Vikram Parimi Jul 20 '15 at 06:35
  • Oky.. I ll test tonight and let u know. – RakeshBiswal Jul 20 '15 at 08:13
  • i need single line not multiple section.I am not able to add screen shot file here .Can u please share me ur personal mail id – RakeshBiswal Jul 20 '15 at 09:05
  • yes, i have implemented through collection view,but data is not reloading,Can you please help me out ?? – RakeshBiswal Aug 17 '15 at 04:15
  • where is it not reloading? – Vikram Parimi Aug 17 '15 at 06:28
  • actually what happens,when i am scrolling horizontally and going to last index & when i am coming back backward scrolling 1st and 2nd content missing,so we cant say it it s not reloading.Please give me some tips asap. – RakeshBiswal Aug 17 '15 at 08:39
  • - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SynopsisCollectionViewCell *playingCardCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SynopsisCollectionViewCell" forIndexPath:indexPath]; [playingCardCell setPlayingCard:self.reusableCells[indexPath.item] andFrame:playingCardCell.frame andDescription1:@"HI this is for test"]; return playingCardCell; } – RakeshBiswal Aug 17 '15 at 08:44
0

There are two main things wrong in your implementation:

  1. in your cellForRowAtIndexPath, you need to initialise the cell for the given indexPath, even if it is a reused cell (if cell != nil).
  2. in your sideButtonClicked, do not call cellForRowAtIndexPath in order to find the cell. It will create a completely new cell, instead of returning the one that is on screen. Derive which row it is from the UIButton argument of the method instead.

Have a look at Apple's programming guide.

fishinear
  • 6,101
  • 3
  • 36
  • 84