加载维基百科页面
我想在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哦,原来我需要用 % 替换数组中字符串中的间隙才能作为正确的链接,这样它就会打开。,
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.,