【问题标题】:Unsupported URL Error不支持的 URL 错误
【发布时间】:2015-05-11 20:10:30
【问题描述】:

我有一个表格视图,其中包含来自 RSS 提要的文章。如果我这样设置 URL,它工作正常:

NSURL *url = [NSURL URLWithString:@"http://kyfbnewsroom.com/category/public-affairs/notifications/feed/"];

但是,我正在尝试将此类用于多个 URL,因此我正在尝试将 URL 字符串传递给该类,但是这样做时出现了不受支持的 URL 错误。

在我的主菜单中选择一个提要:

if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
            WebViewController *wvc = [[WebViewController alloc]init];
            [actionAlerts setWebViewController:wvc];
            actionAlerts.urlString = @"http://kyfbnewsroom.com/category/public-affairs/notifications/feed/";
            navController = [[KFBNavControllerViewController alloc]initWithRootViewController:actionAlerts];
            [UIView transitionWithView:appDelegate.window
                              duration:0.5
                               options:UIViewAnimationOptionTransitionFlipFromRight
                            animations:^{
                                appDelegate.window.rootViewController = navController;
                            }
                            completion:nil];
        }

然后在显示文章的表格视图中:

- (void)fetchEntries
{
    xmlData = [[NSMutableData alloc]init];

    // NSURL *url = [NSURL URLWithString:@"http://kyfbnewsroom.com/category/public-affairs/notifications/feed/"];
    NSURL *url = [NSURL URLWithString:self.urlString];

    NSURLRequest *req = [NSURLRequest requestWithURL:url];

    connection = [[NSURLConnection alloc]initWithRequest:req delegate:self startImmediately:YES];
}

【问题讨论】:

  • 尝试在控制台打印url,看看两个url有什么修改
  • 你能发布完整的代码吗?你在哪里调用这个方法“fetchEntries”?
  • fetchEntries 在 initWithStyle 中被调用:

标签: ios nsurl


【解决方案1】:

只需在-(void)fetchEntries 上设置一个断点并尝试记录self.urlString 并验证您是否获得了正确的网址。问题可能是由于错误的 url。

【讨论】:

  • 就是这个原因。提供一个正确的网址,以便它可以正常工作。
  • 您已经提到在 initWithStyle 中调用了 fetchEntries,因此问题可能是您的 self.urlString 属性不会在 init 方法之前设置。设置 self.urlString 后尝试调用 fetchEntries。
猜你喜欢
  • 2017-08-03
  • 2012-07-07
  • 2018-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-02
相关资源
最近更新 更多