0

On a button click I am showing a popover view which is a tableview.

Everything seems to work and the view shows but then disappears in less than a second.

The tableview contains a list of strings and I set the tablecell to be show checkmark.

I notice that table shows all items checked in the split second it is displayed

Anyone knows what I am missing.

Thanks

Hassan

Code to show the popover

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"WholesalersList"]){
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

        WholesalersViewController *vc = segue.destinationViewController;
        vc.wholesalers = [appDelegate.wholesalers mutableCopy];
        if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
            self.wholesalersPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
            [self.wholesalersPopoverController setPopoverContentSize:CGSizeMake(334, 334)];
            //[self.wholesalersPopoverController setDelegate:self];
        }
    }
}

Code in the popover tableview

#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)theTableView numberOfRowsInSection:(NSInteger)section {
    if ([self.wholesalers count] == 0) {
        return 1;
    }
    else {
        return [self.wholesalers count];
    }
}

#pragma mark Table view delegate
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.wholesalers count] == 0) {
        return nil;
    }
    else {
        static NSString *CellIdentifier = @"WholesalerCell";

        UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];

        // Configure the cell.
        Wholesaler *ws = (Wholesaler *)[self.wholesalers objectAtIndex:indexPath.row];

        cell.textLabel.text = ws.name;

        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)theTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (void)tableView:(UITableView *)theTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;      // The table view should not be re-orderable.
}
soryngod
  • 1,827
  • 1
  • 14
  • 13
Hassan Hussein
  • 157
  • 1
  • 11

1 Answers1

0

Are calling the dismissPopover:Animated anywhere in the code like mistakenly in the IBAction method for the button or you dont have an IBAction method?

ShaluRaj
  • 67
  • 6
  • Echorus I was. Very well spotted! Thank you. I had this code in my IBAction – Hassan Hussein Jul 16 '13 at 06:19
  • if (self.wholesalersPopoverController == nil){ [self performSegueWithIdentifier:@"WholesalersList" sender:self]; } else{ [self.wholesalersPopoverController dismissPopoverAnimated:YES]; self.wholesalersPopoverController = nil; } I don't still know why the else part is executing. And it is because when I commented it out it works. Thanks for spotting that H – Hassan Hussein Jul 16 '13 at 06:24