最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose

来源:动视网 责编:小采 时间:2020-11-27 16:00:08
文档

StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose

StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose:自定义Segue StoryBoard三种连接中,有一种类型是Custom,开发者可以使用自定义的Segue,自定义Segue类需要继承类UIStoryBoardSegue,并重写perform方法: - (void)perform{ NSLog(@使用自定义连接); [self.sourceViewCon
推荐度:
导读StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose:自定义Segue StoryBoard三种连接中,有一种类型是Custom,开发者可以使用自定义的Segue,自定义Segue类需要继承类UIStoryBoardSegue,并重写perform方法: - (void)perform{ NSLog(@使用自定义连接); [self.sourceViewCon


自定义Segue

StoryBoard三种连接中,有一种类型是Custom,开发者可以使用自定义的Segue,自定义Segue类需要继承类UIStoryBoardSegue,并重写perform方法:

- (void)perform{ NSLog(@"使用自定义连接"); [self.sourceViewController presentViewController:self.destinationViewController animated:YES completion:nil];}

Ctrl连线ViewController的按钮到ViewController2,并选择Segue类型为Custom,点击连接,并将连接的类别设置为刚刚自定义的PresentSegue。



运行效果和直接使用Modal类型连接效果一样:


当然也可以自定义Push类型的连接


页面传值

如果希望页面之间的内容有所关联,则需要实现页面间传值,在StoryBoard中,页面传值是通过prepareForSegue:sender:方法实现。先设置连接的Identifier为2vc2(可以根据自己的需要命名,保持跟代码中的字符串一致就OK)


拖拽一个UITextView实例到页面2上,并关联输出口recTextView



在ViewController.m中添加如下代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([[segue identifier] isEqualToString:@"2vc2"]) { ViewController2 *vc2 = (ViewController2 *)[segue destinationViewController]; vc2.passText = @"使用prepareForSegue:sender进行页面传值"; }}
在ViewController2.m中把passText的值赋给recTextView.text

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. _recTextView.text = _passText;}

模拟器运行:

文档

StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose

StoryBoard初探(三):自定义Segue以及页面间传值_html/css_WEB-ITnose:自定义Segue StoryBoard三种连接中,有一种类型是Custom,开发者可以使用自定义的Segue,自定义Segue类需要继承类UIStoryBoardSegue,并重写perform方法: - (void)perform{ NSLog(@使用自定义连接); [self.sourceViewCon
推荐度:
标签: 页面 html ):
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top