在 UIImagePickerController 之后显示 UIViewController

发布于 2024-12-28 14:11:07 字数 699 浏览 4 评论 0原文

我知道这是 iPhone 编程的热门问题,但我还找不到好的答案。

我有一个基于 UITabBarController 的应用程序,中间的 tabBarItem 覆盖有自定义按钮。此自定义按钮用于发布新项目。就像这个(我使用Instagram,例如)。

当然,这个按钮必须在整个应用程序中都可以访问。 当您单击此按钮时,您将看到一个 UIImagePickerController,用于从库或相机中选择图像。

问题是如何在选择图像后显示另一个 UIViewController

第一种方法是从 UIImagePickerController 委托方法设置一个布尔变量,并重写 all 视图控制器的 viewDidAppear 方法来检查布尔变量,如果它是TRUE,调用[self.tabBarController PresentModalViewController:MyControlleranimated:YES]。但我觉得这个实在是太丑了。

你还有其他(优雅的)方法吗?

I know this is a hot question for iPhone programming but I can't find a good answer yet.

I've an UITabBarController based application with the middle tabBarItem overlayed by a custom button. This custom button is used for posting a new item. Like this (I take Instagram, for example).

Of course this button must be accessible in the whole application.
When you click on this button you'll can see an UIImagePickerController for choosing an image from your library or from the camera.

The problem is how to display another UIViewController after you've chosen the image.

The first method is set a boolean variable from the UIImagePickerController delegate method and override the viewDidAppear method of all view controllers for checking the boolean var and if it's TRUE, call [self.tabBarController presentModalViewController:MyController animated:YES]. But I think this one is pretty ugly.

Have you others (elegant) method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇柔作态 2025-01-04 14:11:07

创建一个新的 UIImagePickerControllerDelegate 对象,捕获用户操作,并呈现模式视图控制器或向视图控制器发送消息来处理它。

Create a new UIImagePickerControllerDelegate object, trap user actions, and either present a modal view controller or send a message to a view controller to handle it.

∞觅青森が 2025-01-04 14:11:07

假设 ViewController A 是您单击启动 UIImagePickerController 的相机按钮的类。 ViewController A应该是UIImagePickerController的委托。

然后,在 ViewController A 类中,我们定义单击“使用”按钮时调用的函数。

// This function is invoked when you click the button USE
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
    // Go back to the view A
    [self dismissModalViewControllerAnimated:NO];
    // Get Image
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    // Go to view B
    [self.navigationController pushViewController:showMapViewController animated:NO];

Let's say ViewController A is the class where you click on the camera button starting UIImagePickerController. ViewController Ashould be the delegate of UIImagePickerController.

Then, in ViewController A class, we define the function which is called when you click on the button Use.

// This function is invoked when you click the button USE
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{   
    // Go back to the view A
    [self dismissModalViewControllerAnimated:NO];
    // Get Image
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    // Go to view B
    [self.navigationController pushViewController:showMapViewController animated:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文