第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

通過segue傳遞數(shù)據(jù)

通過segue傳遞數(shù)據(jù)

冉冉說 2019-08-02 16:05:29
通過segue傳遞數(shù)據(jù)我正在使用tableview控制器和detailView進(jìn)行簡單的iOS應(yīng)用程序。我想要的只是通過segue傳遞數(shù)據(jù)。這就是它的樣子。我只想點(diǎn)擊“Markíza”它將打開URL視頻編號(hào)1,如果你點(diǎn)擊“TV JOJ”,它將在播放器中打開URL視頻編號(hào)2。我的tableview單元格:    struct Program {         let category : String         let name : String     }    var programy = [Program]()         self.programy = [Program(category: "Slovenské", name: "Markíza"),                          Program(category: "Slovenské", name: "TV JOJ")]
查看完整描述

3 回答

?
紅糖糍粑

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊

Swift的工作方式與Obj-C完全相同,但在新語言中重新編寫。我的帖子中沒有很多信息,但是讓我們?yōu)槊總€(gè)TableViewController命名,以幫助我解釋。

HomeTableViewController(這是你上面的截圖)

PlayerTableViewController(這是你想去的玩家屏幕)

話雖如此,在PlayerTableViewController中你需要有一個(gè)存儲(chǔ)傳遞數(shù)據(jù)的變量。在你的類聲明下就有這樣的東西(如果你打算將結(jié)構(gòu)存儲(chǔ)為單個(gè)對象而不是數(shù)組:

class PlayerTableViewController: UITableViewController {

    var programVar : Program?

    //the rest of the class methods....

之后,有兩種方法可以將數(shù)據(jù)發(fā)送到新的TableViewController。

1)使用prepareForSegue

在HomeTableViewController的底部,您將使用prepareForSegue方法傳遞數(shù)據(jù)。以下是您將使用的代碼示例:

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

    // Create a variable that you want to send    var newProgramVar = Program(category: "Some", name: "Text")

    // Create a new variable to store the instance of PlayerTableViewController 
    let destinationVC = segue.destinationViewController as PlayerTableViewController
    destinationVC.programVar = newProgramVar    }}

一旦PlayerTableViewController加載,變量將已經(jīng)設(shè)置并可用

2)使用didSelectRowAtIndexPath

如果需要根據(jù)選擇的單元格發(fā)送特定數(shù)據(jù),則可以使用didSelectRowAtIndexPath。為此,您需要在故事板視圖中為您的segue命名(如果您需要知道如何執(zhí)行此操作,請告訴我)。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    // Create a variable that you want to send based on the destination view controller 
    // You can get a reference to the data by using indexPath shown below    let selectedProgram = programy[indexPath.row]

    // Create an instance of PlayerTableViewController and pass the variable    let destinationVC = PlayerTableViewController()
    destinationVC.programVar = selectedProgram    // Let's assume that the segue name is called playerSegue    // This will perform the segue and pre-load the variable for you to use    destinationVC.performSegueWithIdentifier("playerSegue", sender: self)}

如果您需要任何其他信息,請告訴我


查看完整回答
反對 回復(fù) 2019-08-02
?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

使用Swift 3和4

在第一個(gè)ViewController中(發(fā)送值)

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "MainToTimer") {
        let vc = segue.destination as! YourViewController
        vc.verificationId = "Your Data"
    }}

在第二個(gè)viewController(Catch The Value)中

var verificationId = String()


查看完整回答
反對 回復(fù) 2019-08-02
?
米琪卡哇伊

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果您不需要通過標(biāo)識(shí)符識(shí)別操作,只能通過目標(biāo)類識(shí)別...

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let vc = segue.destination as? YourViewController {
        vc.var_name = "Your Data"
    }}


查看完整回答
反對 回復(fù) 2019-08-02
  • 3 回答
  • 0 關(guān)注
  • 597 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)