iOS TableViewController in PopOver disappears after touching tableview

落花浮王杯 提交于 2020-01-04 06:48:07

问题


I am developing universal iOS app and try to achieve popover. I have tried WYPopoverController and FPPopover but those 2 does the same issue.

I have simple UITableViewController having 10 cells putting a static text on each cell (just for a test).

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
     return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];

    UILabel *label = (UILabel *) [cell viewWithTag:1];
    [label setText:@"test"];

    return cell;
}

and try to show this in popover.

Sample code to apply FPPopover is

- (IBAction)test:(id)sender {
    PopOverTableViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"PopOverTableViewController"];

    FPPopoverController *popOver = [[FPPopoverController alloc] initWithViewController:vc];

    [popOver presentPopoverFromView:sender];
}

This shows text in 10 cells at a button tap but once I scroll inside of tableview, the texts disappear and non of tableview data source methods are called afterwards.

It happened for both WYPopoverController and FPPopover so I am assuming there is something wrong in my side. However, I could not figure out where I went wrong.

I appreciate your help on this.


回答1:


Thank you guys for answering my question. I solved myself. It was due to having FPPopoverController as in local variable. I needed to put as instance variable with strong property, otherwise the controller is deallocated by ARC. That made a popover frame is still visible but table view content inside of popover is dismissed.




回答2:


I am not sure what FFPopoverController does but in case of a normal popover controller you can use popover delegate method "popoverControllerShouldDismissPopover" to restrict the disappearance of a popover like following:

-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
    return NO;
}

Surely, you need to declare UIPopoverControllerDelegate to the .h file of your view controller and set the "delegate" property of the popover controller to "self", for the above method to work.



来源:https://stackoverflow.com/questions/19788624/ios-tableviewcontroller-in-popover-disappears-after-touching-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!