我有一個按鈕,我在視圖控制器中以編程方式創建。一旦按下按鈕,我希望它使用一種方法以編程方式創建彈出窗口。如何以編程方式從也是以編程方式創建的uibutton以編程方式顯示彈出窗口(不使用接口生成器)
其在viewDidLoad中創建的我認爲Controller.m或者
UIView *moreFundInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 540, 620)];
[self.view addSubview:moreFundInfoView];
[moreFundInfoView setBackgroundColor:[UIColor RMBColor:@"b"]];
btnContact = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
[btnContact setFrame:CGRectMake(390, 575, contactButton.width, contactButton.height)];
btnContact.hidden = NO;
[btnContact setTitle:@"Contact" forState:(UIControlStateNormal)];
[moreFundInfoView addSubview:btnContact];
[btnContact addTarget:self action:@selector(showContactDetails:) forControlEvents:UIControlEventTouchUpInside];
按鈕然後,我有該按鈕被按下時,我使用的方法。
-(void) showContactDetails: (id) sender
{
UIViewController *popoverContent = [[UIViewController alloc]init];
UIView *popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
[popoverView setBackgroundColor:[UIColor RMBColor:@"b"]];
popoverContent.view = popoverView;
popoverContent.contentSizeForViewInPopover = CGSizeMake(200, 300);
UIPopoverController *contactPopover =[[UIPopoverController alloc] initWithContentViewController:popoverContent];
[contactPopover presentPopoverFromRect:btnContact.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES ];
[contactPopover setDelegate:self];
}
缺少什麼我在這裏?導致它運行良好,但只要我點擊按鈕應用程序崩潰。我認爲這是一個代表問題,但我不確定。任何意見,將不勝感激。
你能給我們碰撞記錄嗎?這將有助於瞭解問題出在哪裏 –
@ValentinRocher仍然是n00b的一部分,但這是崩潰時的輸出。 appname- [UIPopoverController dealloc]在popover仍然可見的情況下到達。[uipopoverController dealloc]到達時彈出窗口仍然可見。 – Berns
嗨,我設法修復它,無論如何,太好了。我只是將UIPopoverController的屬性更改爲強壯,並且它可以工作,只是它指向下而不是向上,但它至少顯示並且應用程序不會崩潰。 – Berns