2017-10-06 2 views
0

UITableViewは1つのViewControllerに2つあり、UIViewがあります.PeekとPopを実装しようとしていますが、両方のテーブルを登録するたびに、 。上記1つのUIViewControllerで複数のUITableViewにピークとポップを実装

 if tableView.point(inside: tableViewPoint, with: nil) { 
      guard let indexPath = self.tableView.indexPathForRow(at: location) else { return nil } 
      guard let cell = self.tableView.cellForRow(at: indexPath) else { return nil } 
      let storyBoard = UIStoryboard(name: "Home", bundle: nil) 
      guard let previewViewController = storyBoard.instantiateViewController(withIdentifier: "article_page") as? ArticleViewController else { return nil } 
      previewViewController.preferredContentSize = CGSize(width: 0.0, height: 550) 

      previewViewController.passedValue = article_ids[(indexPath as NSIndexPath).row] 

      previewingContext.sourceRect = cell.frame 
      return previewViewController 
     } else { 
      guard let indexPath = self.tableView2.indexPathForRow(at: location) else { return nil } 
      guard let cell = self.tableView2.cellForRow(at: indexPath) else { return nil } 
      let storyBoard = UIStoryboard(name: "Home", bundle: nil) 
      guard let previewViewController = storyBoard.instantiateViewController(withIdentifier: "article_page") as? ArticleViewController else { return nil } 
      previewViewController.preferredContentSize = CGSize(width: 0.0, height: 550) 
      if indexPath.row == 0 { 
       previewViewController.passedValue = 1001 
      } else { 
       previewViewController.passedValue = weekly_article_id_[(indexPath as NSIndexPath).row - 1] 
      } 
      previewingContext.sourceRect = cell.frame 
      return previewViewController 
     } 

動作しません:

if traitCollection.forceTouchCapability == UIForceTouchCapability.available { 
    registerForPreviewing(with: self, sourceView: self.tableView2) 
    registerForPreviewing(with: self, sourceView: self.tableView) 
} 

マイviewControllerForLocation:以下は、私がUITableViewsを登録しています場所です。 (おそらく間違った実装は私には意味をなさない)。私もthisソリューションを試しましたが、期待通りに動作しません。私が探しているのは次のようなものです:

if sourceView == tableView { 
//first tableView implementation 
} else { 
//second tableView implementation 
} 

何か助けていただければ幸いです。私は最後の4時間頭をひっぱっている。

答えて

1

私は、おそらくソースビューは、ちょうどあなたのビューであることで、一度だけプレビューするための登録を試してみた:

registerForPreviewing(with: self, sourceView: self.view) 

次に、あなたにpreviewingContext方法それがあるかを判断するために、それぞれのtableViewにこの点を変換します。

let tableViewPoint = self.view.convert(location, to: self.tableView) 
if let indexPath1 = self.tableView.indexPathForRow(at: tableViewPoint) { 
    // Point is within first table - get the cell at this indexPath and handle 
} 
else { 
    let tableViewPoint2 = self.view.convert(location, to: self.tableView2) 
    if let indexPath2 = self.tableView2.indexPathForRow(at: tableViewPoint2) { 
     // Point is within second table - get the cell at this indexPath and handle 
    }    
} 
+0

魅力的な作品です!ありがとう! –

関連する問題