加载维基百科页面

发布于 2024-08-15 02:00:17 字数 762 浏览 4 评论 0原文

我想在 UIAlertView 中创建一个按钮来打开维基百科页面,主题存储在我的数组“array”中,

这是我的做法。

维基百科遵循 http://en.wikipedia.org/wiki/ 的格式。在我的数组中,我有主题的文本条目。我希望它在点击时在移动 Safari 中打开。到目前为止,还没有运气:(

请帮忙。任何见解将不胜感激。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {

NSString *myString = [[NSString alloc] init];

myString = [array objectAtIndex:myInteger];

NSURL *theURL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki/"];
NSString *halfURL = [NSString stringWithFormat:@"%@", theURL];
NSString *fullURL = [halfURL stringByAppendingString:myString];

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

}

I want to make a button in an UIAlertView that opens a Wikipedia page, with a subject stored in my array "array"

Here is how I'm doing it.

Wikipedia follows the format of http://en.wikipedia.org/wiki/<subject>. In my array, I have text entries of subjects. I want it to open in mobile Safari when tapped. So far, no luck :(

Help please. Any insight would be appreciated.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {

NSString *myString = [[NSString alloc] init];

myString = [array objectAtIndex:myInteger];

NSURL *theURL = [NSURL URLWithString:@"http://en.wikipedia.org/wiki/"];
NSString *halfURL = [NSString stringWithFormat:@"%@", theURL];
NSString *fullURL = [halfURL stringByAppendingString:myString];

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

}

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

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

发布评论

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

评论(1

静谧幽蓝 2024-08-22 02:00:17

哦,原来我需要用 % 替换数组中字符串中的间隙才能作为正确的链接,这样它就会打开。,

oh, turns out that i needed to replace the gaps in the strings in the arrays with % to work as a proper link, so it would open.,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文