我正在尝试在屏幕上的某处创建一个简单的弹出框,但由于某种原因它一直在崩溃。它没有给我任何错误(僵尸对象已启用)
UIViewController *viewController = [[UIViewController alloc] init];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
view.backgroundColor = [UIColor redColor];
viewController.view = view;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:viewController];
[popover presentPopoverFromRect:CGRectMake(0, 0, 100, 100) inView:self.view.superview permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
我只是想在随机位置创建一个弹出框,这不可能吗?
编辑:也试过这样
@property (nonatomic, retain) UIPopoverController *popover;
@synthesize popover = _popover;
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor redColor];
_popover = [[UIPopoverController alloc] initWithContentViewController:viewController];
_popover.delegate = self;
[_popover presentPopoverFromRect:CGRectMake(0, 0, 200, 200) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
EDIT2:它可能是相关的,我忘了提到,但是这个代码正在另一个视图中被调用。
这很好用!
UIViewController *viewController = [[UIViewController alloc] init];
viewController.contentSizeForViewInPopover = CGSizeMake(200, 200);
viewController.view.backgroundColor = [UIColor redColor];
UIPopoverController *popver1 = [[UIPopoverController alloc] initWithContentViewController:viewController];
[popver1 presentPopoverFromRect:CGRectMake(250, 200, 200, 200) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
DocumentViewController *document = [[DocumentViewController alloc] initWithIssue:_readerModel.currentIssue];
[self.navigationController pushViewController:document animated:YES];
当我在 DocumentViewController 中调用相同的 EXACT 代码时,它不起作用。