>  Q&A  >  본문

objective-c - storyboard页面跳转和传值

网上查了一些文章,找到一些storyboard页面跳转和传值的方法,试了一下,有一些有用,有的没用,现归纳如下(页面A跳转到页面B),
跳转的方法:
1、A中有button等控件,直接按住control键拖拽到B,点击button可实现跳转;
2、按住control直接将A和B链接,选中连线添加Identifier(命名为c吧)。为A中的button创建action,action里实现方法[self performSegueWithIdentifier:@"c" sender:nil];可实现跳转

传值方法:
1、在prepareForSegue里面实现,根据连线Identifier。传值成功
2、在action里面实现,通过storyboard id找到要跳转的页面,实现跳转和传值UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ReceiveViewController *B = [storyboard instantiateViewControllerWithIdentifier:@"IdReceive"];
B.name = @"GC";
B.age = 10;
[self.navigationController pushViewController:receive animated:YES];

这种方法传值没有成功,页面也不能跳转,因为A是viewcontroller不是navigationController,所以我将最后一句改成[self performSegueWithIdentifier:@"c" sender:nil];跳转可以了,但是传值失败。

请教各位高手,通过storyboard id怎么跳转怎么传值?谢谢!

PHP中文网PHP中文网2727일 전768

모든 응답(1)나는 대답할 것이다

  • PHP中文网

    PHP中文网2017-05-02 09:31:33

    1. navigationviewcontroller 안에 A를 넣었나요? 그러면 마지막 문장을 바꿀 필요가 없습니다

    2. navgationviewcontroller에 없는 경우 B를 표시하려는 방법에 따라 다릅니다. 예를 들어 존재하는 경우 [selfpresentViewController:B animation:YES 완성:nil]

    3. 이런 방식으로 [self PerformSegueWithIdentifier:@"c" sender:nil]을 사용하려면 액션에서 B 뷰 컨트롤러를 가져올 필요가 없습니다.

    으아아아

    회신하다
    0
  • 취소회신하다