国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

點擊TableView中某行進入下一級界面(Swift)

2019-11-14 20:03:45
字體:
來源:轉載
供稿:網友

  TableView這個控件在iOS的開發中非常的常見,他可以較好的展示一個層級結構。這里主要介紹,在點擊某個條目的時候,如何進行跳轉的下一個界面。以下是官方的關于這個跳轉如何去實現,和如何去傳遞數據的過程。

  

Storyboards make it easy to pass data from one scene to another via the PRepareForSegue:sender: method of the UIViewController class. This method is called when the first scene (the source) is about to transition to the next scene (the destination). The source view controller can implement prepareForSegue:sender: to perform setup tasks, such as passing information to the destination view controller about what it should display in its table view. Listing 3-1 shows one implementation of this method.

Storyboards利用func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)將數據從一個界面傳輸到另外一個界面。這個函數在源界面切換到目標界面的時候會調用。所以在源View Controller中可以重載func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)這個方法,在該方法內完成將數據傳送到目的View Controller。下面就是這個函數一般的實現方式。
(Objective-C)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{if ([[segue identifier] isEqualToString:@"ShowDetails"]) { MyDetailViewController *detailViewController = [segue destinationViewController]; NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; detailViewController.data = [self.dataControllerobjectInListAtIndex:indexPath.row];} }


(Swift)

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

        if(segue.identifier == "ShowDetails"){

            var detailViewController:MyDetailViewController ! = segue.destinationViewController as MyDetailViewController

       var index = tableView.indexPathForSelectedRow()

            detailViewController.data = dataController[index!.row]

        }

}

 
A segue represents a one-way transition from a source scene to a destination scene. One of the consequences of this design is that you can use a segue to pass data to a destination, but you can’t use a segue to send data from a destination to its source. To solve this problem, you create a delegate protocol that declares methods that the destination view controller calls when it needs to pass back some data.

Segue是條從源界面到目標界面的一條路。你可以通過Segue將數據從源界面->目標界面。

 以上的過程是在tableViewCell與DetailView界面建立Segue連接的情況下,并且設置了Segue的identifer。

Segue是完全在Storyboard可以拖拽建立,比較簡單,關于如何建立Segue請網上查找下資料。

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沾化县| 班玛县| 繁峙县| 陇南市| 从化市| 前郭尔| 上思县| 乐陵市| 佛冈县| 张掖市| 长宁区| 大埔县| 遂平县| 安徽省| 晋城| 镇安县| 新干县| 仙居县| 鄂尔多斯市| 自贡市| 新昌县| 正宁县| 绥芬河市| 安图县| 宜宾市| 城步| 定结县| 青阳县| 临武县| 柞水县| 阿图什市| 玛曲县| 宾川县| 三台县| 闸北区| 噶尔县| 聂荣县| 青河县| 武清区| 余江县| 道孚县|