问题
i have a dynamic tableviewcontroller SideBarTableViewController.m/.h .
Have a pop up view controller - popUpViewController.m/.h
Have subclassed a cell of SideBarTableViewController -> RegisterTableViewCell.m/.h and added a button outlet from the cell to it.
Have connected the cell to popUpViewController in storyboard using "present As popover" segue and the segue is given identifier "popover". The anchor point in storyboard has been set to Tableview for now , changing it later in preparesegue .
RegisterTableViewCell.h
@property (weak, nonatomic) IBOutlet UIButton *PopoverAnchorButton;
SideBarTableViewController.m
#import "RegisterTableViewCell.h"
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"popover"] && segue.destinationViewController.popoverPresentationController){
UIPopoverPresentationController *popController = segue.destinationViewController.popoverPresentationController;
popController.sourceView = sender;
RegisterTableViewCell *cell = [[RegisterTableViewCell alloc]init];
segue.destinationViewController.popoverPresentationController.sourceRect = CGRectMake(cell.PopoverAnchorButton.frame.size.width/2, cell.PopoverAnchorButton.frame.size.height, 0, 0);
popController.delegate = self;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
RegisterTableViewCell *regcell = [[RegisterTableViewCell alloc]init];
[regcell.PopoverAnchorButton addTarget:self action:@selector(PresentPopover:) forControlEvents:UIControlEventTouchUpInside];
// Configure the cell...
return cell;
}
-(void) PresentPopover:(UIButton *)sender
{
NSLog(@"present popover called ");
[self performSegueWithIdentifier:@"popover" sender:sender];
}
popUpViewController.m
- (IBAction)closeview:(id)sender {
[self.view removeFromSuperview];
}
Problem:
The popup is displayed from the left end of the cell, but wat i see , there is a delay in popup presentation . Normally , first click in the cell, popup comes up as expected ,
second click -> little delay ,
third -> little more delay ... (delay not always increasing though, but fixed 6-7 seconds )
let the ipad be idle for say 6 seconds , and again click in the cell, popup shows immediately .
double clicking(2 taps ) in the cell displays it immediately but with a warning :
2016-07-11 22:53:05.462 Player-app_03[1947:590814] Warning: Attempt to present <UINavigationController: 0x125026400> on <SideBarTableViewController: 0x124d258f0> which is already presenting (null)
What is happening here ? i am clueless. Anybody please help.
回答1:
The problem is likely to be found in the actions of the segue.destinationViewController
, which, from the OP code, appears itself to handle another view controller. To get a handle on this, omit the prepareForSegue
logic that you have, and omit anything in the destination vc's viewDidLoad
or viewWillAppear
that is related to vc presentation.
The segue.destinationViewController
is the view controller that's going to get presented. Anything that messes with that is asking for trouble.
The increasing lag time is very likely caused by the action (inaction, rather) in closeview
, which is merely removing the popup view controller's view, leaving the view controller itself around indefinitely. The proper action in that method is to call:
[self dismissViewControllerAnimated:YES completion:nil];
Also, please note that any place you directly allocate a table view cell (done twice in the OP code), is indicative of at least a misunderstanding, and probably a mistake.
来源:https://stackoverflow.com/questions/37663578/popover-in-uitableviewcell-not-coming-immediately