日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一种storyboard+swift实现页面跳转的方法

發(fā)布時間:2025/3/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一种storyboard+swift实现页面跳转的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一種storyboard+swift實現頁面跳轉的方法

如題。視圖控制器A顯示視頻列表;視圖控制器B顯示視頻詳情,現希望將兩個視圖關聯起來,點擊A中某個視頻跳轉到B。

?

作為iOS小菜鳥我首先搜索了一下關鍵詞 “tableviewcell 跳轉”,然而搜索結果多為object-C、xib、.m文件相關的文檔,已看暈,最后在stackoverflow上找到一篇看得懂的問答。題主在Storyboard上將UITableViewCell與視圖控制器B關聯起來,但是并不知道如何關聯數據。

題目下方有網友表示:“實現prepareForSegue方法就好啦!”

那么prepareForSegue究竟屬于哪個protocol或class,如何在類中實現prepareForSegue方法,segue的生命周期又是怎樣的呢?經過查閱文檔得出如下結論:

1. 定義:Segue表示storyboard文件中兩個ViewController之間的轉換(?)。通常由A視圖控制器的按鈕、表格行或手勢指向B視圖控制器。

2. 觸發(fā):由UIKit實現,可使用notifications在A、B間傳輸數據。segue被觸發(fā)后工作流程如下,提供shouldPerformSegueWithIdentifier:sender:方法中止跳轉所需的步驟,如不新建segue和B;提供prepareForSegue:sender:方法傳輸數據。

?

3. 類型:show是把B堆在A上,detail用B替換A,Modally用模版顯示B,Popover用B作彈窗。

Table 9-1Adaptive segue types

Segue type

Behavior

Show (Push)

This segue displays the new content using the?showViewController:sender:?method of the target view controller. For most view controllers, this segue presents the new content modally over the source view controller. Some view controllers specifically override the method and use it to implement different behaviors. For example, a navigation controller pushes the new view controller onto its navigation stack.?

UIKit uses the?targetViewControllerForAction:sender:method to locate the source view controller.

Show Detail (Replace)

This segue displays the new content using the?showDetailViewController:sender:?method of the target view controller. This segue is relevant only for view controllers embedded inside a?UISplitViewController?object. With this segue, a split view controller replaces its second child view controller (the detail controller) with the new content. Most other view controllers present the new content modally.

UIKit uses the?targetViewControllerForAction:sender:method to locate the source view controller.

Present Modally

This segue displays the view controller modally using the specified presentation and transition styles. The view controller that defines the appropriate presentation context handles the actual presentation.?

Present as Popover

In a horizontally regular environment, the view controller appears in a popover. In a horizontally compact environment, the view controller is displayed using a full-screen modal presentation.

?

那么接下來該行動啦!

1. 選中cell,關聯cell與B,segue類型選擇selection show (detail)

2. 在A對應的Controller中覆蓋prepareForSegue方法,把數據傳給B

class AController: UIViewController, UITableViewDataSource,UITableViewDelegate {

? ? // ...

? ??// 目前只有一個segue,所以沒有判斷viewControllerId,產生錯誤再學怎么區(qū)分

? ? override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

? ? ? ? let index : Int = (self.table.indexPathForSelectedRow?.row)!

? ? ? ? let data:VideoSummary = videoSummaries[index]

? ? ? ? let view : BController = segue.destinationViewController as! VideoViewController

? ? ? ? view.selectedVideo = data

? ? }

}

?

3. 在B對應的Controller中添加selectedVideo屬性

class BController: UIViewController , UITableViewDataSource,UITableViewDelegate {

? ? var selectedVideo : VideoSummary! // 注意感嘆號

? ? //...

}

4. 在B對應的Controller中設置視頻詳情

class BController: UIViewController , UITableViewDataSource,UITableViewDelegate {

? ? //...

? ??override func viewDidLoad() {

? ? ??if(selectedVideo.title.containsString("...")){

? ? ? //...

? ?}

? ? //...

}

// 成功。

?

posted on 2016-06-15 21:47 大俠去哪兒 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/yinkw/p/5589008.html

總結

以上是生活随笔為你收集整理的一种storyboard+swift实现页面跳转的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。