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

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

@selector()在SWIFT?

@selector()在SWIFT?

犯罪嫌疑人X 2019-06-06 11:15:54
@selector()在SWIFT?我想創(chuàng)造一個NSTimer在……里面Swift但我有點麻煩。NSTimer(timeInterval: 1, target: self, selector: test(), userInfo: nil, repeats: true)test()是同一個類中的函數(shù)。我在編輯器中發(fā)現(xiàn)了一個錯誤:無法找到接受所提供的參數(shù)的“init”重載當我改變selector: test()到selector: nil錯誤消失。我試過:selector: test()selector: testselector: Selector(test())但什么都沒用,我在推薦信中找不到解決辦法。
查看完整描述

3 回答

?
回首憶惘然

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

下面是一個關(guān)于如何使用SelectorSWIFT班級:

override func viewDidLoad() {
    super.viewDidLoad()

    var rightButton = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("method"))
    self.navigationItem.rightBarButtonItem = rightButton}func method() {
    // Something cool here   
}

注意,如果作為字符串傳遞的方法不起作用,它將在運行時失敗,而不是編譯時,并使應(yīng)用程序崩潰。注意


查看完整回答
反對 回復(fù) 2019-06-06
?
溫溫醬

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

另外,如果您的(SWIFT)類不是從Object-C類降下來的,那么在目標方法名稱字符串的末尾必須有一個冒號,并且您必須在目標方法中使用@objc屬性。

var rightButton = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("method"))
@objc func method() {
    // Something cool here   
}

否則,您將在運行時得到“未識別的選擇器”錯誤。


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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