I have an iPad app (XCode 5.1.1, iOS 7.1, ARC and Storyboards). I have a UITableView
that calls other UIViews
and UITableViews
. (oServicesCell is outlined in image below)
Normally, when the user taps the Services row, I display another UITableView
of data. However, there are times when I need to display a UIPopover
rather than the `UITableView.
This is the code I'm using, which works but the anchor disappears when the the normal UITableView
is shown (the UIPopover
is also shown... I can see it before the app crashes with -[UIPopoverController dealloc] reached while popover is still visible.).
#pragma mark prepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"segueStartTime"]) {
DateTime *dt = (DateTime *)segue.destinationViewController;
dt.whichTextField = @"oStartTime";
}
else if ([segue.identifier isEqualToString:@"segueEndTime"]) {
DateTime *dt = (DateTime *)segue.destinationViewController;
dt.whichTextField = @"oFinishTime";
}
else if ([segue.identifier isEqualToString:@"segueFromServices"]) {
SingletonServicesType *sharedInstance = [SingletonServicesType sharedServicesType];
// initialize
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView;
SZTextView *activityField;
UIPopoverController *popoverController;
if([sharedInstance.globalServicesType isEqual: @3]) { // "manual entry"?
popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 150)]; // was 216
popoverContent.preferredContentSize = CGSizeMake(250.0, 150.0);
activityField = [[SZTextView alloc] init];
activityField.frame = CGRectMake(0, 0, 250, 150);
activityField.placeholder = NSLocalizedString(@"Enter your activity for this appointment only",nil);
[activityField becomeFirstResponder];
// add it to the popover
popoverContent.title = NSLocalizedString(@"manual",nil);
[popoverView addSubview:activityField];
popoverContent.view = popoverView;
// if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = (id)self;
[popoverController setPopoverContentSize:CGSizeMake(250, 150) animated:NO];
// show it
[popoverController presentPopoverFromRect: oServicesCell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
}
}
How do I prevent the transfer of control the the UITableView
? All I want to do is display the UIPopover
.