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

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

什么是StoryBoard ID,我該如何使用它?

什么是StoryBoard ID,我該如何使用它?

波斯汪 2019-08-12 18:18:07
什么是StoryBoard ID,我該如何使用它?我是IOS的新手,最近開始使用Xcode 4.5。我看到每個(gè)viewController都可以設(shè)置一些身份變量,包括故事板ID。這是什么以及如何使用它?我開始在stackoverflow上搜索,但找不到任何解釋。我認(rèn)為這不僅僅是一些愚蠢的標(biāo)簽,我可以設(shè)置為記住我的控制器嗎?它有什么作用?
查看完整描述

2 回答

?
手掌心

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

故事板ID是一個(gè)String字段,您可以使用該字段創(chuàng)建基于該Storyboard ViewController的新ViewController。一個(gè)示例用法來自任何ViewController:

//Maybe make a button that when clicked calls this method- (IBAction)buttonPressed:(id)sender{
    MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];

   [self presentViewController:vc animated:YES completion:nil];}

這將基于您命名為“MyViewController”的故事板ViewController創(chuàng)建一個(gè)MyCustomViewController,并將其顯示在當(dāng)前View Controller之上

如果您在app代理中,則可以使用

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle: nil];

編輯:斯威夫特

@IBAction func buttonPressed(sender: AnyObject) {
    let vc = storyboard?.instantiateViewControllerWithIdentifier("MyViewController") as MyCustomViewController
    presentViewController(vc, animated: true, completion: nil)}

編輯Swift> = 3:

@IBAction func buttonPressed(sender: Any) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "MyViewController") as! ViewController
    present(vc, animated: true, completion: nil)}

let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)


查看完整回答
反對 回復(fù) 2019-08-12
?
九州編程

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

要添加到Eric的答案并為Xcode 8和Swift 3更新它:

故事板ID完全符合名稱的含義:它標(biāo)識(shí)。只是它識(shí)別故事板文件中的視圖控制器。這是故事板知道哪個(gè)視圖控制器是哪個(gè)。

現(xiàn)在,不要被名字搞糊涂。故事板ID不能識(shí)別“故事板”。根據(jù)Apple的文檔,故事板“代表了應(yīng)用程序全部或部分用戶界面的視圖控制器?!?nbsp;所以,當(dāng)你有類似下圖的內(nèi)容時(shí),你有一個(gè)名為Main.storyboard的故事板,它有兩個(gè)視圖控制器,每個(gè)視圖控制器都可以給出一個(gè)故事板ID(它們在故事板中的ID)。

您可以使用視圖控制器的故事板ID來實(shí)例化并返回該視圖控制器。然后,您可以按照自己的意愿操縱并呈現(xiàn)它。要使用Eric的示例,假設(shè)您想在按下按鈕時(shí)呈現(xiàn)帶有標(biāo)識(shí)符“MyViewController”的視圖控制器,您可以這樣做:

@IBAction func buttonPressed(sender: Any) {
    // Here is where we create an instance of our view controller. instantiateViewController(withIdentifier:) will create an instance of the view controller every time it is called. That means you could create another instance when another button is pressed, for example.
    let vc = storyboard?.instantiateViewController(withIdentifier: "MyViewController") as! ViewController
    present(vc, animated: true, completion: nil)}


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

添加回答

舉報(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)