2017-09-04 9 views
0

私はUITableViewを持つ私のアプリ用の今日のウィジェットを持っています。ユーザーが行をタップするたびに、メインのiOSアプリを開いて、UIViewControllerUITableViewと移動し、対応するセルを選択します。TableViewを開いて行を選択

私は、アプリを開くために知って、私はこのようなものだろう:

let url = URL(string: "ProjectName://") 
extensionContext?.open(url!, completionHandler: nil) 

をして行を選択するために、私はこれを行うだろう:私はすべて一緒にこれを行うだろうか

tableView.selectRowAtIndexPath(index, animated: true, scrollPosition: UITableViewScrollPosition.middle) 

しかし今日のウィジェットからは?文字列として//indexPath.row

最終的指標に基づいて

プロジェクト名:// 1 プロジェクト名:文字列として

答えて

1

CONVERあなたの指標とは、カスタムURLスキーム

プロジェクト名を追加します//2

その後

let url = URL(string: "ProjectName://1") 
extensionContext?.open(url!, completionHandler: nil) 
アペンド値で

を使用して、メインのアプリにリダイレクト

それはそこにあなたがそれを観察し、のInt

に変換し、あなたののViewControllerのInt

 func application(_ application: UIApplication, open urls: URL, sourceApplication: String?, annotation: Any) -> Bool { 

       let obj = urls.absoluteString.components(separatedBy: "://")[1] 

//Here convert string to object back to int 
       NotificationCenter.default.post(name:"selectrow", object: obj) 


      return true 
     } 

に戻って変換することによって、あなたのインデックスを取得することができ、あなたのメインアプリのアプリケーションデリゲートを呼び出します。 In viewDidLoad

NotificationCenter.default.addObserver(self, selector: #selector(ViewController.navigateToPushnotificationScreen), name: "selectrow", object: nil) 

次にこのメソッドを追加します

func navigateToPushnotificationScreen(notification : NSNotification){ 

     let index = notification.object as! String 
     //Here convert your string object to Int, and select your tableview 
    } 
関連する問題