我对视图和呼叫按钮下面的空隙与图像拾取开酥料饼的控制器视图中显示,这里没有问题酥料饼拿出影像选择器等运行时创建的控件没有窗口。 Popovers不能从没有一个窗口
当我创建UIButton的编程方式上viewDidLoad中的按钮调用下面但是这个时候抛出异常相同作废“Popovers不能从没有一个窗口视图中。”
-(IBAction)pickupPhoto:(id)sender
{
CGRect rect = CGRectMake(100, 100, 1, 1); // [(UIScrollView *)sender frame];
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.popOver = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
[popOver setDelegate:self];
[popOver presentPopoverFromRect:rect inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
[imgPicker release];
}
这里我就与创建按钮视图按钮称为空白。
-(void)addButtons
{
for (int i = 0; i < 10; i++) {
self.btn = [[UIButton alloc] initWithFrame:CGRectMake(i * 100, 0, 100, 80)];
[[self.btn layer] setBorderColor:RGB(245, 245, 245).CGColor];
[[self.btn layer] setBorderWidth:1.0f];
[[self.btn titleLabel] setFont:[UIFont fontWithName:@"Thonburi" size:70]];
[self.btn setTitle:doubleToString(i+1) forState:UIControlStateNormal];
[self.btn setTitleColor:RGB(245, 245, 245) forState:UIControlStateNormal];
[self.btn setTitle:doubleToString(i+1) forState:UIControlStateSelected];
[self.btn setTitleColor:RGB(125, 225, 225) forState:UIControlStateHighlighted];
[self.btn addTarget:[NMBPostUI alloc] action:@selector(pickupPhoto:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[btn release];
}
}
我可以看到,当我打电话 - (无效)addButtons,self.view.window返回nil在运行时引起该问题产生的按钮。是的,我应该在初始化时创建按钮,但是当您将视图控制器称为-storyBoard- Page Sheet时没有初始化调用。我怎么能走过这个?
任何想法都欢迎。 非常感谢。
好的,这次是在代码中调用并在init中创建按钮。没有改变。 – mohacs