基于在第一个视图控制器中按下的按钮,xcode 在第二个视图控制器中打开 url [英] xcode open url in second view controller based on button pressed in first view controller

查看:30
本文介绍了基于在第一个视图控制器中按下的按钮,xcode 在第二个视图控制器中打开 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是初学者的问题.所以请耐心等待.我有两个视图控制器.

This is beginner question. So please have a patience. I have two view controllers.

第一个 ViewController 有两个按钮.当按下第一个按钮时,我想打开带有 Google 网址的 TargetViewController,当按下第二个按钮时,我想打开带有 Yahoo 网址的相同 TargetViewController.

First ViewController has two buttons. When the first button is pressed I would like to open TargetViewController with url to Google and when the second button is pressed I would like to open same TargetViewController with url to Yahoo.

我已经创建了演示项目,您可以在这里下载:https:///www.dropbox.com/s/uxjudu1hztyhmk2/Demo.zip?dl=0

I have create demo project you can download here: https://www.dropbox.com/s/uxjudu1hztyhmk2/Demo.zip?dl=0

如果您能提供帮助,请以简单的方式完成此操作,并解释您所做的每个步骤.如果您可以重新上传钓鱼和工作示例,那将会有很大帮助.

If you can help please finish this in simple way with explaining each step you made. It would be a lot of help if you could re upload fished and working example.

我尝试预览相同问题/问题的答案,但它们有多个错误,像我这样的初学者无法解决它们.谢谢你.

I tried previews answers to the same problem/question but they have multiple errors and beginner like me is unable to solved them. Thank you.

推荐答案

你应该在storyboard中设置segue的标识符并在viewController中实现:

You should set segue's identifier in storyboard and implement in viewController:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController* secondController = segue.destinationViewController;
    if ([segue.identifier isEqualToString:@"first"])
    {
        secondController.url = [NSURL URLWithString:@"firstURL"];
    }
    else
    {
        secondController.url = [NSURL URLWithString:@"secondURL"];
    }
}

我更新了你的项目…https://www.dropbox.com/sh/csilubh5ztndy0r/AADZ-hygkod1TRo8a?dl=0?dl=0

这篇关于基于在第一个视图控制器中按下的按钮,xcode 在第二个视图控制器中打开 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆