国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

objective-c - storyboard頁(yè)面跳轉(zhuǎn)和傳值
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-02 09:29:33
0
1
928

網(wǎng)上查了一些文章,找到一些storyboard頁(yè)面跳轉(zhuǎn)和傳值的方法,試了一下,有一些有用,有的沒(méi)用,現(xiàn)歸納如下(頁(yè)面A跳轉(zhuǎn)到頁(yè)面B),
跳轉(zhuǎn)的方法:
1、A中有button等控件,直接按住control鍵拖拽到B,點(diǎn)擊button可實(shí)現(xiàn)跳轉(zhuǎn);
2、按住control直接將A和B鏈接,選中連線添加Identifier(命名為c吧)。為A中的button創(chuàng)建action,action里實(shí)現(xiàn)方法[self performSegueWithIdentifier:@"c" sender:nil];可實(shí)現(xiàn)跳轉(zhuǎn)

傳值方法:
1、在prepareForSegue里面實(shí)現(xiàn),根據(jù)連線Identifier。傳值成功
2、在action里面實(shí)現(xiàn),通過(guò)storyboard id找到要跳轉(zhuǎn)的頁(yè)面,實(shí)現(xiàn)跳轉(zhuǎn)和傳值UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ReceiveViewController *B = [storyboard instantiateViewControllerWithIdentifier:@"IdReceive"];
B.name = @"GC";
B.age = 10;
[self.navigationController pushViewController:receive animated:YES];

這種方法傳值沒(méi)有成功,頁(yè)面也不能跳轉(zhuǎn),因?yàn)锳是viewcontroller不是navigationController,所以我將最后一句改成[self performSegueWithIdentifier:@"c" sender:nil];跳轉(zhuǎn)可以了,但是傳值失敗。

請(qǐng)教各位高手,通過(guò)storyboard id怎么跳轉(zhuǎn)怎么傳值?謝謝!

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證0級(jí)講師

全部回復(fù)(1)
Ty80
  1. 你的 A 是放到 navigationviewcontroller 里面的嗎? 那么最后一句就不用改了

  2. 如果不是在 navgationviewcontroller 里面 ,就看你想怎么展示你的 B 了, 比如 present 的話, 可以 [self presentViewController:B animated:YES completion:nil]

  3. 如果你要用[self performSegueWithIdentifier:@"c" sender:nil]; 這種方式, 就不用在 action 里面獲取 B viewcontroller 了, 代碼修改如下

- (void)someButtonClicked:(id)sender {
  [self performSegueWithIdentifier:@"c" sender:nil]
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender {
 if([segue.identifier isEqualToString:@"c"]){
    ReceiveViewController *B = segue.destinationViewController;
    B.name = @"GC"; 
    B.age = 10; 
    }
}
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板