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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

選擇UITableViewCell時如何進行推送選擇

選擇UITableViewCell時如何進行推送選擇

慕慕森 2019-11-11 12:55:38
我在表格視圖中有一個效果列表。我創(chuàng)建了一個右上方的按鈕,可以將按鈕推送到另一個視圖控制器,這有助于創(chuàng)建新的效果?,F(xiàn)在,我想向表視圖單元格添加推式序列,以便可以將效果值加載到添加效果視圖控制器上,并且可以保存編輯后的值。問題是我可以以編程方式創(chuàng)建推送搜索嗎?如果不能,我可以通過prepareforsegue嗎?如果嘗試使用prepareforsegue,則會遇到一個問題,即從中拖動控件UITableView無法使我創(chuàng)建到添加效果視圖控制器的推送按鈕。
查看完整描述

3 回答

?
翻翻過去那場雪

TA貢獻2065條經(jīng)驗 獲得超14個贊

control 從View Controller拖動到View Controller


從View Controller到View Controlle!


您需要為您的segue提供一個標識符:


執(zhí)行segue:


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [self performSegueWithIdentifier:@"yourSegue" sender:self];

}

現(xiàn)在這是事情,如果您需要將一些數(shù)據(jù)傳遞給該視圖控制器,它將僅執(zhí)行segue。然后,您必須實現(xiàn)以下segue委托:


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    // Make sure your segue name in storyboard is the same as this line

    if ([[segue identifier] isEqualToString:@"yourSegue"])

    {

        //if you need to pass data to the next controller do it here

    }

}


查看完整回答
反對 回復 2019-11-11
?
慕桂英546537

TA貢獻1848條經(jīng)驗 獲得超10個贊

迅速

該答案顯示了如何傳遞數(shù)據(jù),并針對Xcode 8和Swift 3進行了更新。


這是設置項目的方法。


使用創(chuàng)建一個項目TableView。請參閱此處的簡單示例。

添加第二個ViewController。

從具有表格視圖的第一視圖控制器到第二視圖控制器的控制拖動。選擇“顯示”作為segue類型。

單擊情節(jié)提要中的segue,然后在“屬性檢查器”中,將標識符命名為“ yourSegue”。(您可以隨意調(diào)用它,但還需要在代碼中使用相同的名稱。)

(可選)您可以通過在情節(jié)提要中選擇第一個視圖控制器,然后轉(zhuǎn)到編輯器>嵌入>導航控制器,將所有內(nèi)容嵌入到導航控制器中。

具有TableView的First View控制器:


import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


    // ...



    // method to run when table view cell is tapped

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


        // Segue to the second view controller

        self.performSegue(withIdentifier: "yourSegue", sender: self)

    }


    // This function is called before the segue

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {


        // get a reference to the second view controller

        let secondViewController = segue.destination as! SecondViewController


        // set a variable in the second view controller with the data to pass

        secondViewController.receivedData = "hello"

    }

}

第二視圖控制器


class SecondViewController: UIViewController {


    @IBOutlet weak var label: UILabel!


    // This variable will hold the data being passed from the First View Controller

    var receivedData = ""


    override func viewDidLoad() {

        super.viewDidLoad()


        print(receivedData)

    }

}

有關(guān)在視圖控制器之間傳遞數(shù)據(jù)的更基本的示例


查看完整回答
反對 回復 2019-11-11
?
白衣染霜花

TA貢獻1796條經(jīng)驗 獲得超10個贊

這是另一個選項,不需要使用didSelectRowAtIndexPath。


您只需將Interface Builder中的序列從原型單元連接到目標即可。


從那里您可以簡單地:


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

    if segue.identifier == "AffiliationDetail", let destination = segue.destinationViewController as? AffiliateDetailViewController {

        if let cell = sender as? UITableViewCell, let indexPath = tableView.indexPathForCell(cell) {

            var affiliation = affiliations[indexPath.row]

            destination.affiliation = affiliation

        }

    }

}


查看完整回答
反對 回復 2019-11-11
  • 3 回答
  • 0 關(guān)注
  • 533 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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