- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 NavigationController,另一个 Controller 被压入其堆栈:BNRDetailsViewController。现在,在 BNRDetailsViewController 中,我试图在按下工具栏按钮时显示一个弹出窗口,这会向我显示 UIImagePickerController(仅在 iPad 设备上)。因此,我尝试遵循以下 stackoverflow 线程:
UIPopoverPresentationController on iOS 8 iPhone
但是没有成功。如果我只使用他们的代码,我会收到一条错误消息,指出 pushing navigationController is not supported
。如果我尝试像这样推送新创建的 UIPopoverPresentationController
:[self.navigationController pushViewController:self.imagePickerPopover animated:YES];
它会崩溃,因为 UIPopoverPresentationController
不是 UIViewController
类型,所以,我想,我不能只是将它压入堆栈。
在这种特殊情况下,您建议做什么?
这是我现在拥有的代码,它在按下工具栏按钮时触发:
- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// If the device have camera, take a picture, otherwise,
// just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
// Place image picker on the screen
//[self presentViewController:imagePicker animated:YES completion:NULL];
// Place image picker on the screen
// Check for iPad device before instantiating the popover controller
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Create a new popover controller that will display the imagePicker
_imagePickerPopover = [[UIPopoverPresentationController alloc] initWithPresentedViewController:imagePicker presentingViewController:self];
imagePicker.preferredContentSize = CGSizeMake(280, 200);
_imagePickerPopover.delegate = self;
_imagePickerPopover.sourceView = self.view;
CGRect frame = [[sender valueForKey:@"view"] frame];
frame.origin.y = frame.origin.y + 20;
_imagePickerPopover.sourceRect = frame;
// [self.navigationController pushViewController:self.imagePickerPopover animated:YES];
}
}
最佳答案
这是基于您的代码的代码,它将使弹出窗口显示在 iPad 上。
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
imagePicker.modalPresentationStyle = UIModalPresentationPopover;
imagePicker.preferredContentSize = CGSizeMake(280, 200);
CGRect frame = [[sender valueForKey:@"view"] frame];
frame.origin.y = frame.origin.y + 20;
UIPopoverPresentationController *popoverController =
imagePicker.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = frame;
[self.navigationController presentViewController:imagePicker
animated:YES completion:nil];
}
关于iOS,PopOverPresentationController 问题,.xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713482/
我正在决定使用 MonoTouch 进行开发时哪些地方需要使用 .xib 文件。 我当前的项目需要与 iPhone 和 iPad 配合使用,所以我想知道使用 Interface Builder 是
我出于某个目的创建了 4 个宽度为 200、高度为 200 的 xib……但是如果我想在一个 xib 中加载所有 xib,我不知道如何实现……我有几个想法 1.能否让所有的xib都按组数组加载? 2.
我正在处理 Ipad 的应用程序。在这个应用程序中,我的第一类 Xib 上有一个 UIButton,现在我想在单击按钮时在第一类 XIB 中添加第二类 XIB。我知道如何调用第二类 XIB ..就是这
我的第二个 View Controller 中有标签。我想将按钮索引从 firstviewcontroller 传递到 secondviewcontroller 标签。当我按下按钮时,它转到第二个 V
描述:- 我正在为自定义框架编码,为此我到处都使用 XIB,现在我想在我现有的 XIB 中调用另一个 XIB,它的调用非常好但无法执行调用 XIB 的按钮操作。提前致谢 这是代码。 let bundl
我正在寻找一种方法来重用一个 .xib 文件中的内容并将其加载到多个其他 .xib 文件中。原因是我可以在我的应用程序的所有页面上重复使用我的部分设计。我知道在 android 编程中,您可以通过在设
我知道 View XIB 已经有一个 View ,但是还有其他差异吗?我读过的教程说创建一个 View XIB,更改类并删除 View ,然后插入一个 TableView 并重新建立连接(文件所有者到
首先,这是我的 View 层次结构: - Table view -- Table view cell (loaded from custom xib) --- Collection view ----
我想重新使用一些 .xib 文件作为我的 iOS 应用主要 View 的模板。有人能告诉我是否有可能在 iOS 中实现一个“类似模板”的系统,例如:Header、Logo、Footer,并将它们作为单
我如何设置一个 ViewController 来根据某些情况显示一个 View 或另一个 View ? 我有 ViewControllerA.xib 和 ViewControllerB.xib。两者都
有一些类似的帖子,但我已经搜索了很多答案,但不幸的是我没有找到。 我想要什么:我正在使用 xib 文件创建 View 。假设它的类是 BaseView。在这个 baseView 中,我有一个自定义 s
我有一个带有 xib 文件/类问题的奇怪的自动布局。我在使用 xib 文件的 Swift 中创建了一个自定义通知 View (UIView 子类)。 当设备以纵向加载时,通知很好。 当我旋转到横向时,
如果我在 ChildView.xib 中创建自定义 UIView - 我如何从 MainWindow.xib 中引用它? 我试图将一个 UIView 拖到 MainWindow.xib 并将其与同一个
我正在使用 IB 设计一个特定的按钮(带有一些标签、imageView 和其他东西)。 然后我想在另一个 xib 中使用那个 xib 对象(按钮),我有 6 个该按钮的对象。 我知道我可以使用类标识符
我在网上搜索了一段时间,但没有找到答案...... 升级到通用应用程序时,Xcode4 是否可以将 iPhone.xib 转换为 iPad.xib?!?在 Xcode 3 中,可以从选定的 iphon
我看过很多关于将 iPhone xib 转换为 iPad xib 的帖子和教程,但我想反其道而行之。 我能找到的唯一资源是: Convert iPad application to iPhone? 并
有什么方法可以使用相同的 xib 为 iPhone4 和 iPhone5 设计我的类吗? 最佳答案 是的,您可以使用相同的 XIB 通过使用自动布局为 iPhone 4 和 iPhone 5 进行设计
是否有键盘快捷键可以从当前的 xib 文件跳转到它的类(ViewController)?然后再次从它的类返回到它的 xib 文件? 我一直使用 ctrl-command-up/down 在标题和源代码
我对 this 有疑问项目,它没有 xib 文件或 Storyboard。该项目使用以下代码立即将 appdelegate 文件调用到主文件中: int retVal = UIApplicationM
我有一个正在运行的应用程序,其中包含一个导航 Controller 、两个 View Controller 、两个 View 、一个模型对象,并且没有 xib 文件。 View 是以编程方式创建的。现
我是一名优秀的程序员,十分优秀!