ios - Xcode 中来自 Plist 的超链接

标签 ios xcode search plist

我的应用程序中有一个按钮,单击该按钮会将您带到存储在 plist 中的企业网站。我可以获得使用此代码的按钮:

 -(IBAction)search:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}

现在如何操作此代码以从已建立的 plist 调用网站。

最佳答案

从 p-list 中获取链接字符串。

NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]];
NSString * urlString = dictionary[@"TheKeyPath"]; // theKeyPath referring to the key that you assigned to the url string in the p-list

那么就很简单了...

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

关于ios - Xcode 中来自 Plist 的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471091/

相关文章:

iOS 在动态表格的顶部创建一个静态单元格

python - 如何在django-sphinx下自动重建Sphinx索引?

mysql - SQL 搜索名称并按最佳匹配排序

ios - 从 URL iOS 加载图像

ios - 如何在 Swift Playground 中获取布局跟踪

ios - "project.app"需要-Onone Swift 优化级别来使用预览

java - 使用用户输入的字符串找到最长的单词

ios - iPhone 应用程序在 WebThread MPVolumeSlider 上崩溃

ios - 如何使用复合 NSPredicate?

ios - 为面向许多客户的项目交换 Xcode 内容的最佳方式是什么?