簡體   English   中英

如何在xcode中從一個表視圖控制器導航到另一個表視圖控制器

[英]how to navigate from one table view controller to another table view controller in xcode

我正在一個項目中發生可能要從一個表視圖控制器移動到另一表視圖控制器的情況

(即)當我單擊表格視圖中的任何單元格時,應該轉到另一個表格視圖。我還需要為每個不同的單元格單擊表格視圖,然后轉到另一個表格視圖。我不知道該怎么做它

1.如何鏈接兩個表視圖控制器

2.那是什么代碼

請幫我

編寫您的第一個表,添加原型單元格,從該單元格創建一個segue到第二個表,然后編寫以下代碼:

     override func prepare(for segue: UIStoryboardSegue, sender: Any!)  
{
            if segue.identifier == "secondTable" //secondTable is identifier for Segue from prototype cell of 1st table to 2nd table.

            {
                let selectedRow = tableView.indexPathForSelectedRow?.row
                let viewController = segue.destination as! seocondViewController //secondViewController is your class for 2nd table.
               // If you also want to pass some data then add that code also.
                }}

這只是概念。 如果您想獲得更清晰的答案,請嘗試發布完整的代碼。 如果您只想要邏輯,這里就是。 這是指向具有表的相似項目的鏈接 ,當單擊任何行時,它將帶您轉到另一個視圖,該視圖是與該特定行相關的Web視圖,盡管不是表視圖,但每一行都有不同的鏈接。 ,但至少可以理解這個概念。

表格視圖的模型是一個數組。您可以嘗試類似的方法。

id anyPartOfMyM = [self.arrayA objectAtIndex:sIndexPath.row];
[self.arrayA removeObject:anyPartOfMyM];
[self.arrayB addObject:anyPartOfMyM];

// the simplest way to update the tables.
[self.tableViewA reloadData];
[self.tableViewB reloadData];

希望這可以幫助....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM