0
當我在ViewDidLoad
方法中添加UIPopoverController
時,它顯示一個空的彈窗視圖。當我添加一個UITapGestureRecognizer
時會發生同樣的事情;它不觸發附加的方法。如果我將代碼放在我的ViewDidAppear
中,它確實有效,但在某些情況下,從不會調用ViewDidAppear
,具體取決於視圖在故事板中的加載位置。UIPopoverController和UITapGestureRecognizer在ViewDidLoad中不工作
這裏是我的代碼:
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view = popoverView;
pickerPopup = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
pickerPopup.delegate = (id)self;
[pickerPopup setPopoverContentSize:CGSizeMake(320, 240) animated:NO];
而且UITapGestureRecognizer
:
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openPicker:)];
[_form_from addGestureRecognizer:tap];