我试图在单击textField时显示popover。问题是,表中的某些单元格有2个字段,当您单击其中任何一个时,弹出窗口将保留在同一位置。看起来popover固定在同一个地方(tableView的中间)。
我已经研究了好几天了,并尝试了一切!
感谢任何人的帮助。
这是我正在使用的代码:
-(void) showPopoverAction:(id)sender {
// Dismiss the keyboard for activeField
[self.activeField resignFirstResponder];
// Store the popover in a custom property for later use.
if (self.popoverController != nil) {
[popoverController release], popoverController = nil;
}
PopoverViewController* popoverViewController = [[PopoverViewController alloc] init];
//popoverViewController.delegate = self;
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
self.popoverController.delegate = self;
CGRect rect = CGRectMake(0, 0, 150, 100);
[self.popoverController setPopoverContentSize:rect.size animated:YES];
[popoverViewController release];
UITextField *me = sender;
UIView *view = (UIView *)me.superview;
UITableViewCell *tableViewCell = (UITableViewCell *)view.superview;
CGRect meRect = [myTableView rectForRowAtIndexPath:[myTableView indexPathForCell:tableViewCell]];
[self.popoverController presentPopoverFromRect:[self.myTableView convertRect:meRect toView:self.view] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}