0

我在 ios 中使用 Today 扩展。

我有多个具有不同信息的视图控制器。我正在使用 Today 扩展在 tableview 中显示一些信息。当单击行时,我想用信息打开相关的视图控制器。

我试过以下代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
   {
      NSURL *url = [NSURL URLWithString:@"ReadText://"];
      [self.extensionContext openURL:url completionHandler:nil];

   }

我在 info.plist 中设置了 url 方案

但使用此代码我只能打开根视图控制器。

感谢您的帮助。

4

1 回答 1

1

是的,您可以通过将自定义数据传递给 urlSchemes 以编程方式打开 customViewController。

NSURL *url = [NSURL URLWithString:@"ReadText://customViewController"];

实现委托方法并从中获取字符串,url然后以customViewController编程方式推送。

 -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
       NSString *viewController =  [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
       if([viewController isEqualToString:@"customViewController"]) {
          //push customViewController on rootViewController
       }
  }
于 2014-12-30T07:28:15.473 回答